Q4.Write a code to find perfect number

Perfect Number :- Perfect number, a positive integer equal to the sum of its proper divisors. The smallest Perfect number is 6, which is the sum of 1, 2 and 3.
For Example:-
Input = 28
Output = 28 is the Perfect Number.
So as we can see that the divisor of 28 is 1, 2, 4, 7, 14, so the sum of all the divisors is 28 (1 + 2 + 4 + 7 + 14 = 28). Therefore, 28 is the Perfect number.

Algorithm for Perfect Number

START
Step 1 – Input the number.
Step 2 – Find all divisors of the number except the number itself.
Step 3 – If the sum of all divisors of the number is equal to the number, then return true. Else, return false.
STOP

Code for Perfect Number

Output

28 is a perfect number.

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number