📜  埃拉托色尼筛 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:44.440000             🧑  作者: Mango

代码示例1
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include 
#include 
#include 

int main()
{
    int n,i,j; //declaring required variables
    scanf("%d",&n); //scanning n(limit numbers)
    bool arr[n+1]; //declaring an array which contains true and false values
    arr[1]=false; //setting the first index to false (1 is not a prime number)
    
    for(i=2;i<=n;i++){
        arr[i]=true; //we are assuming that all the numbers are true which means prime
    }
    
    for(i=2;i