Blog Moved

This website completely moved to new domain. For latest content, visit

Search This Blog

7 Aug 2012

C program to Find the Number is Prime or Not

/ * C program to find the Number is Prime or not-Prime */
 int n,r=1,d=2;
 printf("\n Enter the Number : ");
   printf("\n %d is a Prime Number \n",n);
   exit(0); //to exit from program
 r=n%d; /*we have to do this before while also becuuse
 if while condition fails then r=n%d inside while is not executed*/

  break; //if r==0, then to come out of while loop
  d++; //incrementing d value if(r==0) fails..
if(r==0||n==1) // since 1 is not a prime number
printf("\n %d is not a Prime Number \n",n);
printf("\n %d is a Prime Number \n",n);

Output: (using GNU GCC Compiler with Code::Blocks Compiler)

No comments:

Post a Comment