救命,判断质数!
  • 板块学术版
  • 楼主25温
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/9/23 00:40
  • 上次更新2023/10/27 10:18:10
查看原帖
救命,判断质数!
36341
25温楼主2022/9/23 00:40

打算写一个能输出从2到a的所有质数的程序,结果出来一个4???sos

#include <bits/stdc++.h>
using namespace std;

bool zs(int s) {
	if (s <= 1)
		return false;
	for (int i = 2; i < sqrt(s); i++) {
		if (s % i == 0)
			return false;
	}
	return true;
}

int main() {
	int a;
	cin >> a;
	for (int i = 2; i < a; i++) {
		if (zs(i) == true)
			cout << i;
	}
	return 0;
}
2022/9/23 00:40
加载中...