用数组解决素数问题,高手进来帮下~~
用筛选法求100之间的素数,高手,大虾们帮忙下,谢了!!
#include <stdio.h>
#include <math.h>
int main()
{
int num[100];
for (int i=0; i<100; i++)
num[i] = i + 1;
for (i=1; i<sqrt(100); i++)
{
for (int j=i+1; j <100; j++)
{
if (num[i] != 0 && num[j] != 0)
{
if (num[j] % num[i] == 0)
num[j] = 0;
}
}
}
for (i=1; i<100; i++)
{
if (num[i] != 0)
printf("%3d",num[i]);
}
printf("\n");
return 0;
}