Sunday, November 2, 2014

First of all we all should know what is perfect number?

In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself.
Example: 6, divisor of 6 are 1, 2,3. Sum of divisors is 1+2+3=6.


PROGRAM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
 
int main() {
   int num, i = 1, sum = 0;
 
   printf("Enter a number: ");
   scanf("%d", &num);
 
   while (i < num) {
      if (num % i == 0) {
         sum = sum + i;
      }
      i++;
   }
 
   if (sum == num)
      printf("%d is a Perfect Number", i);
   else
      printf("%d is Non Perfect Number", i);
 
   return 0;
}
Next
Newer Post
Previous
This is the last post.

0 comments:

Post a Comment