打算写一个能输出从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;
}