素数“漏筛法”
#include<stdio.h>#define max 22500
main()
{ unsigned int i,range ,factor ,k;
int a[max];
printf("please input the range:\n");/*指出多大范围内寻找素数*/
scanf("%d",&range);
for(i=2;i<=range;i++) /*初始化*/
a[i]=1;
factor=2;
while(factor<=range)
{ if(a[factor]==1)
{
printf("%d\t",factor);
k=factor;
while(k<=range)
{
a[k]=-1;
k=k+factor;
}
}
factor++;
}
}
坚强依然!永不言苦!永不言败!睇透数据结构!编程编程再编程!-----激情依旧
[此贴子已经被作者于2005-5-11 9:27:26编辑过]