Problem Statement :
Subscribe Please : click here Subscribe Please : click here
Write a program to take a integer number and check whether this number is perfect number or not .
if number is perfect then print "Given number is Perfect number" else print "Given number is not Perfect number".
A number whose sum of factors (excluding the number itself) is equal to the number is called a perfect number. In other words, if the sum of positive divisors (excluding the number itself) of a number equals the number itself is called a perfect number .
Subscribe Please : click here
Example :
First, we find the factors of 496 i.e. 1, 2, 4, 8, 16, 31, 62, 124, and 248. Let's find the sum of factors (1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 +248 = 496). We observe that the sum of factors is equal to the number itself. Hence, the number 496 is a perfect number.
Subscribe Please : click here
If number is 6 then factors of 6 is 1,2,3 and sum of factor is 1+2+3 is also 6 . So 6 is a perfect number .
Approach :
- Read or initialize a number (n).
- Declare a variable (s) for storing sum.
- Find the factors of the given number (n) by using a loop (for/ while).
- Calculate the sum of factors and store it in a variable s.
- Compare the sum (s) with the number (n):
- If both (s and n) are equal, then the given number is a perfect number.
- Else, the number is not a perfect number.
Subscribe Please : click here
Code :
Subscribe Please : click here Subscribe Please : click here
Comments
Post a Comment