c program for prime number || C programming examples || prime number

 c program for prime number || C programming examples || prime number

#include <stdio.h>
 
main()
{
   int n, c;
 
   printf("Enter a number\n");
   scanf("%d", &n);
 
   if ( n == 2 )
      printf("Prime number.\n");
   else
   {
       for ( c = 2 ; c <= n - 1 ; c++ )
       {
           if ( n % c == 0 )
              break;
       }
       if ( c != n )
          printf("Not prime.\n");
       else
          printf("Prime number.\n");
   }
   return 0;
}
Share this Post Share to Facebook Share to Twitter Email This Pin This Share on Google Plus Share on Tumblr join on whatsapp

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment