Brijmohan lal Sahu - Facebook
ads
ads

Thursday, October 30, 2014

Program to check entered number is prime number or not



----------------------------------------

// Program to Check entered number is prime number or not//

#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,y,x,c;
c=0;


clrscr();

cout<<"\n\tPrime Number Checker\n";
cout<<"Enter a number:";
cin>>x;

for(i=2;i<=x;i++)
{
for(j=2;j<i;j++)
{

if(x%j==0)
{c++;
}

}

}
if(c==0)
{
cout<<"Number is prime:"<<x;
}
else
{
cout<<"not prime";
}

getch();
}

No comments:

Post a Comment