This C Program checks whether a given number is perfect number. Perfect number is a number which is equal to sum of its divisor. For eg,divisors of 6 are 1,2 and 3. The sum of these divisors is 6. So 6 is called as perfect number.

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`

`*/`

`#include <stdio.h>`

int main()

`{`

int number, rem, sum = 0, i;

printf("Enter a Number\n");

scanf("%d", &number);

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");

`else`

printf("Entered Number is not a perfect number");

return 0;

`}`

advertisement

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.**

advertisement

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.