In this program, the user is ask to enter a number, then that number is determined whether it is Prime or not.
Prime numbers are special numbers, greater than 1, that have exactly two factors, themselves and 1.
19 is a prime number. It can only be divided by 1 and 19.
The prime numbers below 20 are: 2, 3, 5, 7, 11, 13, 17, 19. ...
#include <iostream>
using namespace std;
int main()
{
int no, i, isPrime = 1;
cout<<"Enter the number : ";
cin>> no;
for (i = 2; i <= no/2; i++)
{
if (no % i == 0)
{
isPrime = 0;
break;
}
}
if (isPrime == 1)
{
cout<<"Prime number" << no;
}
else
{
cout<<"Not a Prime number" << no;
}
return 0;
}
Enter the number : 17
Prime number
Enter the number : 74
Not a Prime number