Here is source code of the C Program to check whether a given number is perfect number. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Check whether a given Number is Perfect Number
int number, rem, sum = 0, i;
printf("Enter a Number\n");
for (i = 1; i <= (number - 1); i++)
rem = number % i;
if (rem == 0)
sum = sum + i;
if (sum == number)
printf("Entered Number is perfect number");
printf("Entered Number is not a perfect number");
Output: $ cc pgm42.c $ a.out Enter a Number 6 Entered Number is perfect number $ a.out Enter a Number 100 Entered Number is not a perfect number
Sanfoundry Global Education & Learning Series – 1000 C Programs.