C program to check whether a number is perfect number or not
Posted by Samath
Last Updated: January 02, 2017

Write a C program to enter any number and check whether the number is Perfect number or not. 
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.

For example: 6 is the first perfect number
Proper divisors of 6 are 1, 2, 3 
And 1+2+3 = 6.


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;
   if (sum == num)
      printf("%d is a Perfect Number", i);
      printf("%d is Non Perfect Number", i);
   return 0;


Related Content
Find Perfect Numbers in C++
Find Perfect Numbers in C++
Samath | Dec 26, 2014