badge

Search Flipkart

Tuesday, June 26, 2012

Optimzed C program for prime number checking

#include
void main(){
int i,j;
int n ;
scanf("%d",&n);
if(n%2==0 && n!=2){
printf(" %d is not prime and is divisible by  2 ",n);
}
else{
for(i=3;iif(n%i==0){
j=1;
printf(" %d is  divisible by  %d \n",n,i);
}
i=i+2;
}
if(j==1)
printf("the number is not prime\n");
else
printf("the number is  prime\n");
}
}