55. C Program To check a Number is Perfect number or Not.
How does this program work?
- This Program is used to check the given number is perfect number or not.
Here is the code
#include <stdio.h>
int main(void)
{
int num, r, sum = 0, i;
printf("Enter a Number\n");
scanf("%d", &num);
for (i = 1; i <= (num - 1); i++)
{
r = num % i;
if (r== 0)
{
sum = sum + i;
}
}
if (sum == num)
printf("Entered Number is perfect number: %d",num);
else
printf("Entered Number is not a perfect number %d",num);
return 0;
}