I want to check a number for prime or not.I tried with loop but I could not print It is prime. I could only print if it is not prime. Also can we use If inside a loop and else outside the loop?How?
#include
using namespace std;
int main() {
//Prime Checker
//The number should not be divisible by 2,3,…N
int i = 2;
int N;
cin>>N;
while(i<N-1){
if(N%i==0){
cout<<“It is not prime”<<endl;
break;
}
i = i + 1;
}
else {
cout<<“It is a Prime”<<endl;
}
return 0;