Wednesday, July 6, 2011

Program to find whether the given number is a Prime numbers


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n=0,i=0,c=0;
cout<<"Enter the number"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
 if(n%i==0)
 c++;
}
if(c<=2)
cout<<"Number is a prime no."<<endl;
else
cout<<"Number is not a prime no."<<endl;
getch();
}

No comments:

Post a Comment