第二題,求用簡單的C++語句啊,大一小白,這是作業表示不會,幫幫忙,
#include
#include
#include
using namespace std;
bool isPrime(int num){
if ((num == 1) || (num == 2)) {
return true;
}
for (int i = 2; i <= num / 2; i++){
if (num % i == 0)
return false;
}
return true;
}
int main(){
int p1 = 2;
for (int p = 2; p <= 100; p++) {
if (isPrime(p)){
if (p - p1 == 2)
cout << "(" << p1 << ", " << p << ")" << endl;
p1 = p;
}
}
return 0;
}