Need a project done?

C++ Programming Developer

Search This Blog

Prime number Check Program C++


#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main(){
bool isPrime = true;
cout << "Enter a number: "; int num; cin >>num;

for (int i = 2; i<num; i++){
if (num % i == 0){
isPrime = false;
break;
}
}
cout << num << " is " << (isPrime? "":"not") << " a prime number" << endl;
return 0;
}

See Also:

How to Calculate Prime Factors?

Prime Number Checker in C++


"Don't let anyone ever make you feel like you don't deserve what you want."