Javatpoint Logo
Javatpoint Logo

Program to print all Pronic numbers between 1 and 100

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

  1. isPronicNumber() determines whether a given number is the Pronic number or not.
    1. Define a boolean variable flag and set its value to false.
    2. 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.
    3. If a match is found, then set the flag to true, break the loop and returns the value of the flag.
  2. To display all Pronic numbers between 1 and 100,
    1. Start a loop from 1 to 100, and make a call to isPronicNumber() method for each value from 1 to 100.
    2. If isPronicNumber() returns true which signifies that number is Pronic, then display that number.

Solution

Python

Output:

Pronic numbers between 1 and 100: 
2 6 12 20 30 42 56 72 90

C

Output:

Pronic numbers between 1 and 100: 
2 6 12 20 30 42 56 72 90

JAVA

Output:

Pronic numbers between 1 and 100: 
2 6 12 20 30 42 56 72 90 

C#

Output:

Pronic numbers between 1 and 100: 
2 6 12 20 30 42 56 72 90 

PHP

Output:

Pronic numbers between 1 and 100: 
2 6 12 20 30 42 56 72 90

Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA