Rectangular (or Pronic) Numbers - GeeksforGeeks

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 rectangular numbers are: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 . . . . . . Given a number n, find n-th rectangular number.Examples:  
Input : 1
Output : 2

Input : 4
Output : 20

Input : 5
Output : 30
 
The number 2 is a rectangular number because it is 1 row by 2 columns. The number 6 is a rectangular number because it is 2 rows by 3 columns, and the number 12 is a rectangular number because it is 3 rows by 4 columns. If we observe these numbers carefully, we can notice that n-th rectangular number is n(n+1). 
 
C++
Java
C#
Python
PHP
Javascript
// CPP Program to find n-th rectangular number#include <bits/stdc++.h>using namespace std; // Returns n-th rectangular numberint findRectNum(int n){    return n * (n + 1);} // Driver codeint main(){    int n = 6;    cout << findRectNum(n);    return 0;}
// Java Program to find n-th rectangular numberimport java.io.*; class GFG {     // Returns n-th rectangular number    static int findRectNum(int n)    {        return n * (n + 1);    }     // Driver code    public static void main(String[] args)    {        int n = 6;        System.out.println(findRectNum(n));    }} // This code is contributed by vt_m.
// C# Program to find n-th rectangular number using System; class GFG {     // Returns n-th rectangular number    static int findRectNum(int n)    {        return n * (n + 1);    }     // Driver code    public static void Main()    {        int n = 6;        Console.Write(findRectNum(n));    }} // This code is contributed by vt_m.
# Python3 Program to find n-th rectangular number # Returns n-th rectangular numberdef findRectNum(n):    return n*(n + 1) # Driver coden = 6print (findRectNum(n)) # This code is contributed by Shreyanshi Arun.
<?php// PHP Program to find n-th// rectangular number // Returns n-th rectangular// numberfunction findRectNum($n){    return $n * ($n + 1);}     // Driver Code    $n = 6;    echo findRectNum($n);     // This code is contributed by ajit?>
<script> // Javascript Program to find n-th rectangular number // Returns n-th rectangular numberfunction findRectNum(n){    return n * (n + 1);} // Driver codevar n = 6;document.write(findRectNum(n)); // This code is contributed by noob2000.</script>
Output:  
42
Check if a given number is Pronic | Efficient ApproachThis article is contributed by DANISH_RAZA . 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. 
jit_t
noob2000
series
Mathematical
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Merge two sorted arrays
Modulo Operator (%) in C/C++ with Examples
Program for factorial of a number
Print all possible combinations of r elements in a given array of size n
Program for Decimal to Binary Conversion
The Knight's tour problem | Backtracking-1
Operators in C / C++
Find minimum number of coins that make a given value
Program to find sum of elements in a given array
Minimum number of jumps to reach end