1-100000内的质数统计
#include <stdio.h>#define MAX 1000
//程序结果:
//1000以内168个
//10000以内1229个
//100000以内9592个
//1000000以内有78498个
void main(void)
{
float num;
int i,n,sum=0,res;
int a,b; //验证本程序正确性
for(num=2,a=2;num<MAX,a<MAX;num++,a++)
{//printf("A%d",a); //验证标志A
for(n=2,b=2;n<(num/2+1);n++,b++)
{//printf("B%d",b); //验证标志B
res=((int)((num/n)*MAX)%MAX);
if(res!=0)
continue;
else goto loop;
}
printf("%6.0f ",num);
sum++;
if((sum%5)==0)
printf("\n");
loop: continue;
}
printf("\n");
printf("1-%d中的质数共有%d个。\n",MAX,sum);
}