Sunday, 15 December 2013

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

Output

 Enter a Number
6
Entered Number is perfect number


Enter a Number
100
Entered Number is not a perfect number

For More Details Please Visit Ictjobs.info

No comments: