programming-examples/c/_Basic/C Program to Check whether a given Number is Perfect Number.c
2019-11-15 12:59:38 +01:00

24 lines
561 B
C

/*
* 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;
}