Facebook Google Plus YouTube

Check perfect number range between 1 to 50.

Check perfect number range between 1 to 50.

Perfect number are summation of divisors of a number exclude the number ownself.

Eample 6,28.

Lets check 28. From 1 to 27 we need to check which number can divide 28.
then sum of all those number whose are divisors of 28.

28 = 1,2,7,14(divisors).

Now make sum of all divisors
1+2+7+14 = 28

so 28 is perfect number.

Again 6 divisors are 1,2,3

so, 1+2+3 = 6 which is also perfect number.

C program:

#include <stdio.h>

int main()
{

int checkNumber,perfectNumber,min=1,max=100,sum;

for(perfectNumber=min;perfectNumber<=max;perfectNumber++)
{
checkNumber=1,sum=0;
while(checkNumber<perfectNumber)
{
if(perfectNumber%checkNumber== 0)
sum= sum+checkNumber;
checkNumber ++;
}
if(sum ==perfectNumber)
{
printf("%d is perfect number\n",checkNumber);
}
}
return 0;
}

 

output: 6 28

 

Leave a Reply

%d bloggers like this: