求500以内的全部素数,每行输出10个do while语句
时间: 2024-01-31 08:49:54 浏览: 56
int num = 2;
do {
int i = 2;
bool isPrime = true;
while (i <= sqrt(num)) {
if (num % i == 0) {
isPrime = false;
break;
}
i++;
}
if (isPrime) {
cout << num << " ";
if (num % 10 == 1) {
cout << endl;
}
}
num++;
} while (num <= 500);
阅读全文