用筛法求100以内的素数

#include<iostream>
int main()
{
    int prime[101]={0};
    for (int i = 2; i<100; i++)
    {
        if(prime[i]==0)
        {
            for(int j=2;i*j<=100;j++)
            {
                prime[i*j]=1;
            }
            prime[0]++;
            std::cout<<i<<",";
        }
    } 
    std::cout<<'\n'<<"Total number:"<<prime[0];  
    while(1);
    return 0; 
}

有不懂的可以给我留言。

猜你喜欢

转载自blog.csdn.net/m0_46606140/article/details/106225394