#include<iostream>
usingnamespace std;
int main(){
int num;
bool prime;
cout << "Please enter a positive integer" << endl;
cin >> num;
for(int i = 2; i <= num; i++){
prime = true;
for(int n = 2; n <= i - 1; n++){
if(i % n == 0){
prime = false;
}
}
if(prime != false){
cout << i << " is prime" << endl;
}
else
cout << i << "is not prime" << endl;
}
return 0;
}
I've used bool Prime instead, and I can't figure out where to go if I have to use his specific function. Any help is much appreciated!!!
if( number is 1 )
returnfalseelseif( number is 2 )
returntrueelseif ( the number is even )
returnfalse //since all even numbers except 2 are not prime
else number is odd
From i = 3 to and including square root of the given number
i is incremented by 2
if number is divisible by i
returnfalsereturntrue; //If the loop terminates, then the number must be prime