#include<iostream>
using namespace std;
int main()
{
unsigned long n,j;
cout<<" Enter a number =";
cin>>n;
for(j=2;j<=n/2;j++)
if(n%j==0)
{
cout<<" it is not prime number "<<j<<endl;
exit(0);
}
cout<<" it is prime \n ";
return 0;
}
A number which is only divisible by itself and 1 is known as prime number, for example: 5 is a prime number because it is only divisible by itself and 1.
This program takes the value of num (entered by user) and checks whether the num is prime number or not.
0 Comments