Here is the coding of C program to check perfect number using while loop
Before getting into the depth, we want to let you know what actually is Perfect number.
Perfect number is those numbers which divisor number’s sum are equal to that number, for more insight lets have a glance in one example.
E.g: 28 is perfect number ! Divisor of number 28 are : 1,2,4,7 & 14 Lets add all these divisor numbers : 1+2+4+7+14 = 28
Hence Sum of divisor of number 28 is equal to 28, that is why 28 is one of the example of perfect number.
Here is C program code to check perfect number using while loop:
int i, num, sum=0;
printf("Enter any number to check perfect number: ");
// Calculate sum of all proper divisors
for(i=1; i<num; i++)
//If i is a divisor of num
if(num%i == 0)
sum += i;
//Check whether the sum of proper divisors is equal to num
if(sum == num)
printf("%d is PERFECT NUMBER", num);
printf("%d is NOT PERFECT NUMBER", num);