Given a positive integer **N**, the task is to find the sum of all the numbers in the **N ^{th}** row of the below triangle.

1

3 2

6 2 3

10 2 3 4

15 2 3 4 5

…

…

…

**Examples:**

Input:N = 2

Output:5

3 + 2 = 5

Input:N = 3

Output:11

6 + 2 + 3 = 11

**Approach:** Taking a closer look at the pattern, it can be observed that a series will be formed as **1, 5, 11, 19, 29, 41, 55, …** whose **N ^{th}** term is

**(N – 1) + N**.

^{2}Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the sum ` `// of the nth row elements of ` `// the given triangle ` `int` `getSum(` `int` `n) ` `{ ` ` ` `return` `((n - 1) + ` `pow` `(n, 2)); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 3; ` ` ` ` ` `cout << getSum(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function to return the sum ` `// of the nth row elements of ` `// the given triangle ` `static` `int` `getSum(` `int` `n) ` `{ ` ` ` `return` `((n - ` `1` `) + (` `int` `)Math.pow(n, ` `2` `)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `n = ` `3` `; ` ` ` ` ` `System.out.println(getSum(n)); ` `} ` `} ` ` ` `// This code is contributed by Code_Mech ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the sum ` `# of the nth row elements of ` `# the given triangle ` `def` `getSum(n) : ` ` ` ` ` `return` `((n ` `-` `1` `) ` `+` `pow` `(n, ` `2` `)); ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `n ` `=` `3` `; ` ` ` ` ` `print` `(getSum(n)); ` ` ` `# This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the sum ` `// of the nth row elements of ` `// the given triangle ` `static` `int` `getSum(` `int` `n) ` `{ ` ` ` `return` `((n - 1) + (` `int` `)Math.Pow(n, 2)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `n = 3; ` ` ` ` ` `Console.WriteLine(getSum(n)); ` `} ` `} ` ` ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

**Output:**

11

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find the Nth row in Pascal's Triangle
- Find the sum of all the terms in the n-th row of the given series
- Program to print a Hollow Triangle inside a Triangle
- Check if Pascal's Triangle is possible with a complete layer by using numbers upto N
- Program to print tetrahedral numbers upto Nth term
- Program to print pentatope numbers upto Nth term
- Find the Nth term of the Zumkeller Numbers
- Find the Nth Hogben Numbers
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Program to find Nth term in the given Series
- Number of digits in the nth number made of given four digits
- Find the nth term of the given series
- Sum of all natural numbers in range L to R
- Sum of all odd natural numbers in range L and R
- Print all Good numbers in given range
- Difference between sum of the squares of first n natural numbers and square of sum
- Sum of sum-series of first N Natural numbers
- Pascal's Triangle

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.