Home C Language Basic C Programs Prime number in C

Prime number in C

Write a C Program to Find Whether the Given Number is Prime Number or not.


int main()


   int a,i,count=0; //’a’ is user defined number, ‘i’ for iteratiions, ‘count’ for counting factor of given number.

   printf(“Enter a number :”);




      if(a%i==0) //check the iteration value is factor of given number or not.



   if(count==2) //Every prime number should have only two factors.

      printf(“Given number is PRIME number\n”);


      printf(“Given number is Non-PRIME number\n”);

   return 0;


Output :

i) Enter a number : 28541

Given number is PRIME number

ii)Enter a number : 30857

Given number is Non-PRIME number