CPP Program For Prime Number

#include<iostream.h>
#include<conio.h>
 
 
void main ()
{
clrscr();
int n,i,x=0;
cout << "enter any number" << endl;
cin >> n;

for(i=2;i<n;i++)
{
if(n%i==0)
{
x++;
}
}
if(x==0)
{
cout << "prime" << endl;
}
else
{
cout << "not prime" << endl;
}
getch();
}

Output:

enter any number
3
prime

 

Leave a Reply