Skip to content
Related Articles

Related Articles

Improve Article
Check if a given number is Pronic
  • Difficulty Level : Easy
  • Last Updated : 24 Mar, 2021

The numbers that can be arranged to form a rectangle are called Rectangular Numbers (also known as Pronic numbers). The first few Pronic numbers are: 
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 . . . . . . 
Pronic number is a number which is the product of two consecutive integers, that is, a number n is a product of x and (x+1). The task is to check and print Pronic Numbers in a range.
Examples : 
 

Input  : 6
Output : Pronic Number
Explanation: 6 = 2 * 3 i.e 6 is a product
of two consecutive integers 2 and 3.

Input :56
Output :Pronic Number
Explanation: 56 = 7 * 8 i.e 56 is a product 
of two consecutive integers 7 and 8. 

Input  : 8
Output : Not a Pronic Number
Explanation: 8 = 2 * 4 i.e 8 is a product of 
2 and 4 which are not consecutive integers.

 

C++




// C/C++ program to check
// if a number is pronic
#include <iostream>
#include <math.h>
using namespace std;
 
// function to check
// Pronic Number
bool checkPronic(int x)
{
 
    for (int i = 0;
            i <= (int)(sqrt(x));
            i++)
 
        // Checking Pronic Number
        // by multiplying consecutive
        // numbers
        if (x == i * (i + 1))
        return true;
 
    return false;
}
 
// Driver Code
int main(void)
{
    // Printing Pronic Numbers
    // upto 200
    for (int i = 0; i <= 200; i++)
        if (checkPronic(i))
            cout << i << " ";
     
    return 0;
}
 
// This code is contributed
// by Nikita Tiwari.

Java




// Java program to check and
// Print Pronic Number upto 200
import java.io.*;
import java.util.*;
import java.math.*;
 
class GFG
{
 
    // function to check Pronic Number
    static boolean checkPronic(int x)
    {
        for (int i = 0;
             i <= (int)(Math.sqrt(x));
             i++)
             
            // Checking Pronic Number
            // by multiplying consecutive
            // numbers
            if (x == i * (i + 1))
                return true;
         
        return false;
    }
 
    // Driver Code
    public static void main(String[] args)
    {
        // Printing Pronic
        // Numbers upto 200
        for (int i = 0; i <= 200; i++)
            if (checkPronic(i))
                System.out.print(i + " ");    
    }
}
 
// This code is contributed
// by Nikita Tiwari

Python




# Python program to check
# and print Pronic Numbers
# upto 200
import math
 
# function to check
# Pronic Number
def checkPronic (x) :
 
    i = 0
    while ( i <= (int)(math.sqrt(x)) ) :
         
        # Checking Pronic Number
        # by multiplying consecutive
        # numbers
        if ( x == i * (i + 1)) :
            return True
        i = i + 1
 
    return False
 
# Driver Code
 
# Printing Pronic
# Numbers upto 200
i = 0
while (i <= 200 ) :
    if checkPronic(i) :
        print i,
    i = i + 1
 
# This code is contributed
# by Nikita Tiwari.

C#




// Java program to check and
// Print Pronic Number upto 200
using System;
 
class GFG
{
 
    // function to check
    // Pronic Number
    static bool checkPronic(int x)
    {
        for (int i = 0;
                 i <= (int)(Math.Sqrt(x));
                 i++)
             
            // Checking Pronic Number by
            // multiplying consecutive numbers
            if (x == i * (i + 1))
                return true;
         
        return false;
    }
 
    // Driver Code
    public static void Main()
    {
        // Printing Pronic
        // Numbers upto 200
        for (int i = 0; i <= 200; i++)
            if (checkPronic(i))
                Console.Write(i + " ");
    }
}
 
// This code is contributed by vt_m.

PHP




<?php
// PHP program to check
// if a number is pronic
 
// function to check
// Pronic Number
function checkPronic($x)
{
 
    for ($i = 0;
         $i <= (sqrt($x));
         $i++)
 
        // Checking Pronic Number
        // by multiplying consecutive
        // numbers
        if ($x == $i * ($i + 1))
        return true;
 
    return false;
}
 
// Driver Code
 
// Printing Pronic
// Numbers upto 200
for ($i = 0; $i <= 200; $i++)
    if (checkPronic($i))
        echo $i , " ";
 
// This code is contributed by Ajit
?>

Javascript




<script>
 
// Javascript program to check
// if a number is pronic
 
// function to check
// Pronic Number
function checkPronic(x)
{
 
    for (var i = 0;
            i <= parseInt(Math.sqrt(x));
            i++)
 
        // Checking Pronic Number
        // by multiplying consecutive
        // numbers
        if (x == i * (i + 1))
        return true;
 
    return false;
}
 
// Driver Code
 
// Printing Pronic Numbers
// upto 200
for (var i = 0; i <= 200; i++)
    if (checkPronic(i))
        document.write(i + " ");
 
// This code is contributed by noob2000
</script>

Output : 
 

0 2 6 12 20 30 42 56 72 90 110 132 156 182

This article is contributed by Nikita Tiwari. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
 

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :