Rectangular (or Pronic) Numbers

1.5

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).

Photo edited with https://www.tuxpi.com

// CPP Program to find n-th rectangular number
#include<bits/stdc++.h>
using namespace std;

// Returns n-th rectangular number
int findRectNum(int n)
{
    return n*(n + 1);
}

// Driver code 
int main()
{
    int n = 6;
    cout << findRectNum(n);
    return 0;
}

Output:

42

This 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.

GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:



1.5 Average Difficulty : 1.5/5.0
Based on 2 vote(s)










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.