C++ Program to Check Prime Number
Here you will get an example code of C++ Program to Check Prime Number.
How to check prime number ?
Example code of C++ Program to Check Prime Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<iostream> using namespace std; int main() { int num,i,flag=0; cout<<"Enter a Numbers: "; cin>>num; for (i = 2; i <= num/2; ++i) { if (num % i == 0) { flag = 1; break; } } if (flag == 0) printf("%d is a prime number.", num); else printf("%d is not a prime number.", num); return 0; } |
Output
Check out our other C++ programming Examples