信息发布→ 登录 注册 退出

输出1000以内的素数的算法(实例代码)

发布时间:2026-01-11

点击量:
代码如下所示:
复制代码 代码如下:
#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;
}
标签:# BR  # pause  # shu  # main  # printf  # Su  # stdafx  # lt  # iostream  # include  # STRONG  # 1000以内的素数  # span  # int  # nbsp  # IsSushuFlg  # IsSushu  # gt  # math  # bool  # 所示  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!