|
The program is to find all the
perfect numbers inside the user defined range. A perfect
number is one, whose sum of devisors is equals the number
itself.
Logic:
This is advanced version of the
previous program. Here, user need to enter two numbers as
the lower and upper limits for the iteration loop to find the
perfect number between that. The outer for loop traces the
iteration till the limit, wherein each of iteration inner for
loop checks the present number is perfect or not,
with
the perfect number's logic. If it is, it prints out the
present number.
In this program, both the lower
limit and the upper limit are variables, and so is flexible.
These three programs show, how we can upgrade the logic to
make the code flexible one.
The similar algorithm can be
used to
find the prime numbers inside a given range.
|