In this article, We will check whether number is prime is not.
Prime Numbers are those numbers which is divisible by 1 and itself. Eg: 2,3,5,7,11 etc.
We will check the prime number by simply dividing all the number below that number. Suppose, If we have to check the 5 then we will divide 5 by 2,3 and 4. If the anyone gives remainder 0 then that is not a prime.
Let’s look and example to make clear concepts
using namespace std;
int num, i, flag = 0;
cout << "Enter a Number: ";
cin >> num;
for( i = 2; i < num; i++)
if( num % i == 0)
flag = 1;
if( flag == 0 )
cout << "\nIt is a Prime Number" << endl;
cout << "\nIt is not a Prime Number" << endl;
The output of above program is
Enter a number : 5
It is a Prime Number
Enter a number : 6
It is not a Prime Number
Let’s understand how program working:
Get the latest tutorials, examples and projects updates.
Ads Blocker Detected!!!
We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.
Disable Ad Block
Want Same System