Auto AdSense

Wednesday, 26 June 2013

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


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

main()
{
      int i,num,sum;

      clrscr();

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

      i = 1;
      sum = 0;
      while(i < num)
      {
              if(num % i == 0)
                  sum = sum + i;
              i++;
      }

      if(sum != num)
          printf("\n The entered number %d is NOT A PERFECT NUMBER",num);
      else
          printf("\n The entered number %d is A PERFECT NUMBER",num);

      return 0;
}

No comments:

Post a Comment