Tuesday 7 May 2013

Program In C To Check Whether A Number Is Prime Number Or Not


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ int num,i;
clrscr();
printf("Enter Number: ");
scanf("%d",&num);
if(num==1)
{printf("It Is Not A Prime Number");
exit(0);}
for(i=2;i<=((num/2)+1);i++)
{ if(num%i==0)
{ printf("It Is Not A Prime Number");
break;}
else if(i==(num/2)+1)
printf("It Is A Prime Number");
}
getch();
}

No comments:

Post a Comment