如何使用C++代码实现1-100之间的素数

#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
int i;
int j=0;
for (i = 2; j <= 100; i++) {
for (j = 2; j <= i; j++) {
if (i%j == 0) {
break;
}
}
if (j >= i) {
cout << i;
//cout << "\n";
}
cout << "\n";
}

}

猜你喜欢

转载自www.cnblogs.com/zgl19991001/p/11309177.html