|

楼主 |
发表于 2004-3-20 11:54:48
|
显示全部楼层
计算1至100间的素数,还有比这个程序更好的算法吗?
- int
- main(void)
- {
- unsigned j,tmp,count;
- for(j=1;j<= 100;j++) {
- count=0;
- for( tmp=((j-(j%2))/2);tmp>1;tmp-- )
- if( j % tmp ==0 ) {
- count =1 ;
- break;
- }
- if(count == 0 )
- printf("%d ",j);
- }
- printf("\n");
- return(0);
- }
复制代码 |
|