Home » ALGORITHM » PERFECT NUMBER ALGORITHM AND FLOWCHART

PERFECT NUMBER ALGORITHM AND FLOWCHART

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

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

FLOWCHART TO GENERATE PERFECT NUMBERS

FLOWCHART TO GENERATE PERFECT NUMBERS

Related Posts

  • ALGORITHM AND FLOWCHART FOR COMPOSITE NUMBERALGORITHM AND FLOWCHART FOR COMPOSITE NUMBER Those numbers which are divisible by other than itself and 1 are known as composite numbers. The number 4 can is divisible by 1, 2 and 4 therefore 4 is a composite number. But 7 is […] Posted in ALGORITHM
  • ALGORITHM TO CHECK EVEN AND ODD NUMBERSALGORITHM TO CHECK EVEN AND ODD NUMBERS A number is said to be even number if it leaves no remainder when divided by 2. There is an alternative definition of even number and it is as a number having any number from 0, 2, 4, 6 […] Posted in ALGORITHM
  • ALGORITHM AND FLOWCHART FOR COPRIME NUMBERALGORITHM AND FLOWCHART FOR COPRIME NUMBER A Coprime number comes in pair of integers. Thus they are defined as those paired numbers which can be divided by the common number 1 are called coprime numbers. Suppose a and b are two […] Posted in ALGORITHM
  • ALGORITHM TO FIND GREATEST COMMON DIVISORALGORITHM TO FIND GREATEST COMMON DIVISOR The GCD or greatest common divisor of two or more positive numbers is the greatest number which divides each number completely (Leaving no remainder). For example 6 and 18 are divisible by […] Posted in ALGORITHM