C Program to Check Whether the Given Number Prime Numbers or Not

0
739

To Check Whether the Given Number is Prime Numbers or Not

Note:

Prime numbers are numbers only divisible by one and itself.

Prime numbers are 2, 3, 5, 7, 11, 13….

#include<stdio.h>
 
main()
{
   int n, c = 2;
 
   printf("Enter a number to check whether it is prime or not\n");
   scanf("%d",&n);
 
   for ( c = 2 ; c <= n - 1 ; c++ )
   {
      if ( n%c == 0 )
      {
         printf("%d is not prime.\n", n);
     break;
      }
   }
   if ( c == n )
      printf("%d is prime.\n", n);
 
   return 0;
}

Leave a Reply