Auto AdSense

Wednesday, 26 June 2013

C PROGRAM TO CHECK WHETHER THE NUMBER READ IS A PRIME NUMBER OR NOT


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

main()
{
      int i,num,flag;

      clrscr();

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

      i = 2;
      flag = 0;

      while(i < num-1)
      {
              if(num % i == 0)
              {
                     flag = 1;
                     break;
              }
              i++;
      }

      if(flag == 1)
          printf("\n The enter number %d is NOT A PRIME NUMBER",num);
      else
          printf("\n The enter number %d is A PRIME NUMBER",num);

      return 0;
}

No comments:

Post a Comment