计算一段区间内的所有素数

论坛 期权论坛 脚本     
匿名技术用户   2020-12-27 00:00   26   0
#include<iostream>
using namespace std;
void prime(int x, int y) {
if (x <= 1) x = 2;
if (y <= 1) return;
for (int i = x; i <= y; i++) {
bool flag = true;
for (int j = 2; j <= sqrt(i); j++) {
if (i%j == 0) flag = false;
}
if (flag == false) continue;
else cout << i << ' ';
}
cout << endl;
}
int main() {
int x,y;
cout << "Input the begin and end:";
cin >> x >> y;

prime(x,y);

return 0;

}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP