Sunday, September 5, 2010

Program to enter an integer and print if it is prime or composite


#include
#include
#include

void main()
{
clrscr();
int num1,x;
cout << "Enter an integer : " << endl;
cin>>num1;
for(x=2;x{
if(num1%x==0)
{
cout << num1 << " is a composite number." << endl;
getch();
exit(0);
}
else
{
cout << num1 << " is a prime number." << endl;
getch();
exit(0);
}
}
}

0 comments:

Post a Comment