by manojthesingham » Tue Sep 01, 2009 6:42 am
#include<stdio.h>
#include<conio.h>
typedef enum{false=0,true=1}boolean;
boolean prime_number(int x)
{
int i;
/*
5 7 11 13 ..... 37 ... 101
6-1 6+1 12-1 12+1 36+1 102-1
*/
if((x==2)||(x==3))
return true;
if(((x+1) % 6 == 0)||((x-1) % 6 == 0))
{
for(i=3;i<(x/2);i+=2)
if((x%i)==0)
return false;
return true;
}
return false;
}
int main(int argc,char **argv)
{
int x;
printf("Enter the number to check whther it is prime or not : ");
scanf("%d",&x);
printf("%s",prime_number(x)?"PRIME Number":"Not A PRIME Number");
getch();
return 0;
}
If world is running, then I am idle..
If I am idle, then the world is running