Here you learn how to check prime number in C++.

Prime number is a number which is only divided by 1 or itself.

Below is the C++ program to check whether a number is prime of not.

## Prime Number in C++

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<iostream> using namespace std; int main() { int n,i,flag=1; cout<<"Enter any number:"; cin>>n; for(i=2;i<=n/2;++i) { if(n%i==0) { flag=0; break; } } if(flag) cout<<"\n"<<n<<" is a Prime number"; else cout<<"\n"<<n<<" is not a Prime number"; return 0; } |

**Output**

*Enter any number:7*

*7 is a Prime number*

he program work perfectly ðŸ™‚ ðŸ™‚ ðŸ™‚

thank you !!!!!