Menu
MENU
Flowchart - Perfect Number or not
Problem Statement
Draw a Flowchart to check whether a number is Perfect or not.
Brief Description
According to the problem statement we have to draw a flowchart that will check whether a given number is perfect or not.
A positive number is perfect if it is equal to the number obtained by adding its proper positive divisors excluding the number itself.
For example, if 6 is given as input, we will get an output indicating that 6 is a perfect number since the number 6 is divisible by 1, 2 and 3 (excluding 6) and 1+2+3=6. But if 8 is given as input, we will get an output indicating that 8 is not a perfect number since the number 8 is divisible by 1, 2 and 4 (excluding 8) and 1+2+4=7.
Flowchart
Explanation
In order to draw the flowchart given above the following steps are taken into consideration:
- Initially 0 is stored in a variable namely sum.
- After that a number is taken as input from the user and is stored in a variable namely num.
- Then 1 is stored in i.
- After that it is checked to see whether the value of i is <= the value of num/2. If it is then the following steps are repeated till the value of i is <= the value of num/2:
- It is checked to see whether the value stored in i is a proper positive divisor of the value stored in num or not.
- If it is then the value stored in i is added with the value stored in sum and the result is stored in the same variable i.e. sum.
- The value of i is incremented by 1.
- It is checked to see whether the value stored in i is a proper positive divisor of the value stored in num or not.
- If the value of i is > the value of num/2 then it is checked to see whether value of num and sum are equal or not
- If it is then we can conclude that the value stored in num is a perfect number and “Perfect” is displayed as output.
- If it is not then we can conclude that the value stored in num is not a perfect number and “Not Perfect” is displayed as output.
Share this page on