Q:

Program to print all Pronic numbers between 1 and 100

belongs to collection: Number Programs

0

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.

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Python

#isPronicNumber() will determine whether a given number is a pronic number or not  
def isPronicNumber(num):  
    flag = False;  
      
    for j in range(1, num+1):  
        #Checks for pronic number by multiplying consecutive numbers  
        if((j*(j+1)) == num):  
            flag = True;  
            break;  
    return flag;  
   
#Displays pronic numbers between 1 and 100  
print("Pronic numbers between 1 and 100: ");  
for i in range(1, 101):  
    if(isPronicNumber(i)):  
        print(i),  
        print(" "),  

 

Output:

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

 

C

#include <stdio.h>  
#include <stdbool.h>  
   
//isPronicNumber() will determine whether a given number is pronic number or not  
bool isPronicNumber(int num){  
    bool flag = false;  
      
    for(int j = 1; j <= num; j++){  
        //Checks for pronic number by multiplying consecutive numbers  
        if((j*(j+1)) == num){  
            flag = true;  
            break;  
        }  
    }  
    return flag;  
}  
   
int main()  
{  
    //Displays pronic numbers between 1 and 100  
    printf("Pronic numbers between 1 and 100: \n");  
    for(int i = 1; i <= 100; i++){  
        if(isPronicNumber(i))  
            printf("%d ", i);  
    }  
   
    return 0;  
}  

 

Output:

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

 

JAVA

public class PronicNumbers  
{  
    //isPronicNumber() will determine whether a given number is pronic number or not  
    public static boolean isPronicNumber(int num){  
        boolean flag = false;  
          
        for(int j = 1; j <= num; j++){  
            //Checks for pronic number by multiplying consecutive numbers  
            if((j*(j+1)) == num){  
                flag = true;  
                break;  
            }  
        }  
        return flag;  
    }  
      
    public static void main(String[] args) {  
          
        //Displays pronic numbers between 1 and 100  
        System.out.println("Pronic numbers between 1 and 100: ");  
        for(int i = 1; i <= 100; i++){  
            if(isPronicNumber(i))  
                System.out.print(i + " ");  
        }  
    }  
}

  

Output:

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

 

C#

using System;  
                      
public class PronicNumbers  
{  
    //isPronicNumber() will determine whether a given number is pronic number or not  
    public static Boolean isPronicNumber(int num){  
        Boolean flag = false;  
          
        for(int j = 1; j <= num; j++){  
            //Checks for pronic number by multiplying consecutive numbers  
            if((j*(j+1)) == num){  
                flag = true;  
                break;  
            }  
        }  
        return flag;  
    }  
      
    public static void Main()  
    {  
        //Displays pronic numbers between 1 and 100  
        Console.WriteLine("Pronic numbers between 1 and 100: ");  
        for(int i = 1; i <= 100; i++){  
            if(isPronicNumber(i))  
                Console.Write(i + " ");  
        }  
    }  
}   

 

Output:

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

 

PHP

<!DOCTYPE html>  
<html>  
<body>  
<?php  
//isPronicNumber() will determine whether a given number is pronic number or not  
function isPronicNumber($num){  
    $flag = false;  
      
    for($j = 1; $j <= $num; $j++){  
        //Checks for pronic number by multiplying consecutive numbers  
        if(($j*($j+1)) == $num){  
            $flag = true;  
            break;  
        }  
    }  
    return $flag;  
}  
   
//Displays pronic numbers between 1 and 100  
print("Pronic numbers between 1 and 100: <br>");  
for($i = 1; $i <= 100; $i++){  
    if(isPronicNumber($i))  
        print($i . " ");  
}  
?>  
</body>  
</html>  

 

Output:

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to determine whether a given number is a D... >>
<< Program to print all happy numbers between 1 and 1...