|
Here is a program to find
whether the entered number is a prime or not. A prime
number is a one, whose divisors are 1 and the number
itself.
Logic:
The program expects the user to
enter the number to check for prime property. The for loop in
the program traces the iteration till the number, while in
each of iteration it checks the present number is the divisor
of the entered or not. If it is, it sets the flag to 1 and
breaks off, which effectively prints out the result through
the if block.
The same algorithm is modified
slightly, and developed a
program to print all the
prime number till the user defined
range.
|