Wednesday, 23 April 2014

6. Write a program to check whether a given number is a perfect number or not. Hint: A positive integer n is called a perfect number if it is equal to the sum of all of its positive divisors. excluding n itself For example, 6 is a perfect number. because 1. 2 and 3 are its proper positive divisors and 1 + 2 + 3 =. 6. The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. The next perfect numbers are 496 and 8128



#include<stdio.h>
#include<conio.h>
void main()
{
          int val,i,j=0;
          clrscr();
          printf("\n\n\tEnter the Number to Check its Perfect or Not -> ");
          scanf("%d",&val);
          for(i=1; i<val; i++)
          {
                   if(val%i==0)
                   {
                             j=j+i;
                   }
          }
          if(j==val)
          {
                   printf("\n\n\t\tYour No is Perfect No");
          }
          else
          {
                   printf("\n\n\t\tYour No is not a perfect no");
          }
          getch();
}

No comments:

Post a Comment