`

用C语言求1-100素数

阅读更多
呵呵,不会的话可以参考! 
#include <stdio.h>
void main ()
{
int i, j, p, prime [ 100 ];
p = 0;
prime [ p ++ ] = 2;
for ( i = 2; i < 101; i ++ )
{
for ( j = 0; j < p; j ++ )
if ( !(i % prime [ j ]) ) break;
if ( j >= p )
prime [ p ++ ] = i;
}
for ( i = 0; i < p; i ++ )
printf ( "%d\n ", prime [ i ] );
return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics