实现代码如下:
#include "stdafx.h"
#include <iostream>
#include <math.h>
bool IsSushu(int n)
{
bool IsSushuFlg = true;
if( n <= 1)
{
return false;
}
for( int i = 2; i <= (int)sqrt((double)n); i++ )
{
if( 0 == n % i )
{
IsSushuFlg = false;
break;
}
}
return IsSushuFlg;
}
#define N 1000
int main()
{
printf("Su shu is: /n");
for( int i = 2; i < N; i++)
{
bool IsSushuFlg = IsSushu(i);
if( IsSushuFlg )
{
printf("%d /n", i);
}
}
system("pause");
return 0;
}
以上就是【输出1000以内的素数的算法(实例代码)】的全部内容了,欢迎留言评论进行交流!