A number is said to be a perfect number if the sum of factors of the number (**excluding number itself as a factor**) is equal to the number itself. Example of perfect numbers are 6, 28, 496, 8128 and so on. The factors of a given number are those numbers which divide the given number completely. For example factors of 28 are 1, 2, 4, 7, 14 and 28. Now the sum 1 + 2 + 4 + 7 + 14 = 28. We can see that 28 is not included in the sum.

## ALGORITHM TO CHECK PERFECT NUMBER

(**Perfect Number)** Let N be positive Integer. This algorithm will check whether N is perfect number or not. To do so we have to find the factors of N. And then we have to add all factors except N. Now we have to compare N with sum of factors (Denoted By SOF in Algorithm). If N is equal to SOF then N is a perfect number. And if N is not equal to SOF then N is not a perfect number.

Step 1: Start

Step 2: [ Take Input ] Read: N

Step 3: [ Initialize ] Set: SOF = 0 and I = 1

Step 4: Repeat While I < N

Check If N%I == 0 Then

Compute: SOF = SOF + I

[ End of If Structure ]

Compute: I = I + 1

[ End of While Loop ]

Step 5: Check If N == SOF Then

Print: N is a Perfect Number.

Else

Print: N is not a Perfect number.

Step 6: Exit

### FLOWCHART TO CHECK PERFECT NUMBER

## ALGORITHM TO GENERATE PERFECT NUMBERS

**(Generate Perfect Numbers)** This algorithm generates perfect numbers within a range. Let R be the range. Each number from 1 to range R is checked whether it is a perfect number or not. If a number is found to be a perfect number then it is printed.

Step 1: Start

Step 2: [ Take Input ] Read: R

Step 3: [ Initialize ] Set: SOF = 0 and a = 1

Step 4: Repeat While a ≠ R

Set: N = a and I = 1

[ Sub Step 4a ] Repeat While I < N

Check If N%I == 0 Then

Compute: SOF = SOF + I

[ End of If Structure ]

Compute: I = I + 1

[ End of Sub Step 4a ][ End of Inner While Loop ]

[ Sub Step 4b ] Check If N == SOF Then

Print: a

[ End of Sub Step 4b ] [ End of If Structure ]

Set: SOF = 0

Compute: a = a + 1

[ End of Outer While Loop ]

Step 5: Exit