 C program to Check if a Number is Perfect

A number is Perfect, if sum of all it’s divisors is equal to the original number.
Example.

consider a number 6, it has 3 divisors, where 1, 2 and 3. Where 1+2+3=6
Hence 6 is a Perfect number.

% is the remainder after division (modulo division) arithmetic operator in C.
11 % 5 = 1 (11 / 5 = 2 with remainder 1)

```/*C Program to find whether the number is
Perfect number or not*/
#include <stdio.h>
void main()
{
int i = 1, num, sum = 0;
printf(" Enter the number:");
scanf("%d", &num);
while (i < num)
{
if (num % i == 0)
sum = sum + i;
i++;
}
if (sum == num)
printf("%d is Perfect Number\n", num);
else
printf("%d is not a Perfect Number\n", num);
}
```
 \$ gcc perfect.c \$ ./a.out Enter the number:6 6 is Perfect Number \$ ./a.out Enter the number:100 100 is not a Perfect Number \$

If you like the post C program to C program to Check if a Number is Perfect or Not please share your feedback!

also see

Previous articleQueue Implementation using Array