Friday, September 23, 2011

WAP to check whether entered number is prime or not



/*
  Name: WAP to check whether entered number is prime or not
  Author: Parveen Malik
  Date: 23/09/11 02:28
*/


#include<stdio.h>
#include<conio.h>


main()
{
   int n, c;


   printf("Enter a number\n");
   scanf("%d", &n);


   if ( n == 2 )
      printf("Prime number.\n");
   else
   {
       for ( c = 3 ; c <= n - 1 ; c++ )
       {
           if ( n %c == 0 )
              break;
       }
       if ( c != n )
          printf("Not prime.\n");
       else
          printf("Prime number.\n");
   }
   getch();
   return 0;
}


OUTPUT : 





0 comments:

Post a Comment