Pages

Subscribe:

Blogger templates

Friday, March 9, 2012

Prime or Composite number

The coding starts from next line:-
---------------------------------------------------------------------------------------------------------------
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void main()
{
clrscr();
int i,num,ans;
cout<<"\nEnter the number you want to check:";
cin>>num;
for(i=2;i<=(num-1);i++)          //(i=2;i<=num/2;i++)
{
if(num%2==0)
{
ans=1;
break;
}
else
{
ans=0;
}
}
if(ans==1)
{
cout<<"\It is a composite number";
}
else {
cout<<"\nits a prime number";
}
getch();
}




0 comments:

Post a Comment