日 历
 
<<  < 2008 - 10 >  >>
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
 
 
 
 
 
静下心来,做点事情!
童言无忌,各位见笑!
 

本站logo

学前班


本站永久域名:

http://BugEyes.blog.edu.cn

 
 
登 陆
 
 
载入中

 
 
我 的 分 类
 
 

载入中

搜索一下

 
 
最 新 日 志
 
 

载入中

 

 
 
朋友的评论
 
 
载入中
 
 
朋友的留言
 
 
载入中
 
 
BLOG 信 息
 
 

创建日期:2005年5月2日

载入中

 

 
 
友 情 连 接
以下连接按先后顺序进行排名
 
   
 


 

朋友们如果转载或引用本站的内容,请尊重作者的劳动,注意保留完整,并注明文章原始url。谢谢!_____________BugEyes

尽管代码丑陋,思想低级,但非注明出处者均为原创文章。

筛选法求素数的算法优化[原创] [ BugEyes 发表于 2005-10-8 11:36:00 ]

#define N 1000

void init(int array[],int n)
{
   int i;
   for(i=0;i<n;i++)
     array[i]=i;
}

void prime(int array[],int n)
{
   int i,j;
   for(i=2;i<n;i++)
     if(array[i]!=0)
       for(j=i+i;j<n;j+=i)
          array[j]=0;
}

void output(int array[],int n)
{
   int i,j=0;
   for(i=2;i<n;i++)
     if(array[i]!=0)
     {
       if(j%5==0)
           printf("\n");
       printf("%4d",array[i]);
       j++;
     }
}

void main()
{
   int arr[N+2];
   init(arr,N+2);
   prime(arr,N+2);
   output(arr,N+2);
}

 

发表评论:
载入中

版权归 学前班校长所有
http:// bugeyes.blog.edu.cn
 
 
Powered by Oblog.