Explanation
In this program, we need to display all Pronic numbers between 1 and 100.
Pronic number
The pronic number can be defined as the number which is a product of two consecutive numbers. Mathematically, the Pronic number can be represented as
N x (N + 1)
To find whether a number n is a Pronic number or not, use for loop to iterate from i = 1 to i = n and check whether i*(i+1) is equal to n for any value of i.
Some of the examples of Pronic numbers are
6 = 2 x 3
72 = 8 x 9
Algorithm
- isPronicNumber() determines whether a given number is the Pronic number or not.
- Define a boolean variable flag and set its value to false.
- Use for loop to iterate from 1 to given number and check whether i * (i + 1) is equal to the given number, for any value of i.
- If a match is found, then set the flag to true, break the loop and returns the value of the flag.
- To display all Pronic numbers between 1 and 100,
- Start a loop from 1 to 100, and make a call to isPronicNumber() method for each value from 1 to 100.
- If isPronicNumber() returns true which signifies that number is Pronic, then display that number.
A number is said to be pronic number if it is a product of two consecutive numbers.
For examples:
6 = 2 x 3
72 = 8 x 9
Input:
range(1, 101)
Output:
Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: