Algorithm to Check if Number is Perfect Number

[19922 views]




What is Perfect Number?

Perfect number is a positive integer equal to the sum of its proper divisors. Sum of its proper divisor excludes the Number itself. Ex. For number 6, the divisors are 1, 2, 3 and 6. Now if we take sum of 1, 2, 3 and exclude the number itself (i.e. 6), the sum is 6. Hence, 6 is a perfect number. 6 is the smallest Perfect Number.

Algorithm to Check if Number is Perfect Number

Let's check another number:
Input: 28
Divisors of 28: 1, 2, 4, 7, 14, 28
Sum of Divisors excluding 28: 1+2+4+7+14=28
Output: 28 is Perfect Number

Algorithm to Check whether given number is Perfect Number:

1. Start 2. Read n 3. Initialize s=0 4. for i=1 to n do a. if(n%i)==0, then b. s=s+i 5. if s==n then Print "Given Number is Perfect Number". Goto Step 7 6. Print "Given Number is Not a Perfect Number" 7. Stop
                 






Comments










Search Anything:

Sponsored Deals ends in



Technical Quizzes Specially For You:

Search Tags

    Pseudocode for Perfect Number

    How to Check if Number is Perfect Number programmatically

    Algorithm for Perfect Number