Home >>Cpp Programs >Prime Number Program In C++

# Prime Number Program In C++

### Prime Number Program In C++

We all have read the basic math and prime number is a part of it. Prime Number Program in C++ is basically a program code that is written to check whether the input entered by the user is a prime number or not. Prime number is basically a number that is greater than 1 and is divisible by 1 or itself. In layman’s terms it can be understood as the numbers that cannot be divided by any number other than itself or 1. For instance, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23.... are known as the prime numbers as they full the definition.

Example:

Here is an example of the prime number program in C++ programming language and in this program, the input will be taken from the user and will be checked whether the entered number is prime number or not.

```#include <iostream>
using namespace std;
int main()
{
int num, a, b=0, flag=0;
cout << "Plese Enter Your Number : ";
cin >> num;
b=num/2;
for(a = 2; a <= b; a++)
{
if(num % a == 0)
{
cout<<"Given number is not Prime number."<<endl;
flag=1;
break;
}
}
if (flag==0)
{
cout << "Given Number is Prime number."<<endl;
}
return 0;
}
```
Output :
Plese Enter Your Number : 3
Given Number is Prime number.
Output :
Plese Enter Your Number : 4
Given Number is not Prime number.