# Sum of all the numbers present at given level in Pascal’s triangle

Given a level L. The task is to find the sum of all the integers present at the given level in Pascal’s triangle .

A Pascal triangle with 6 levels is as shown below:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

**Examples:**

Input:L = 3

Output:4

1 + 2 + 1 = 4

Input:L = 2

Output:2

**Approach:** If we observe carefully the series of the sum of levels will go on like * 1, 2, 4, 8, 16….*, which is a GP series with a = 1 and r = 2.

Therefore, sum of Lth level is L’th term in the above series.

Lth term = 2^{L-1}

Below is the implementation of the above approach:

## C++

`// C++ implementation of the above approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find sum of numbers at ` `// Lth level in Pascals Triangle ` `int` `sum(` `int` `h) ` `{ ` ` ` `return` `pow` `(2, h - 1); ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `L = 3; ` ` ` ` ` `cout << sum(L); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find sum of numbers at ` ` ` `// Lth level in Pascals Triangle ` ` ` `static` `int` `sum(` `int` `h) ` ` ` `{ ` ` ` `return` `(` `int` `)Math.pow(` `2` `, h - ` `1` `); ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `int` `L = ` `3` `; ` ` ` ` ` `System.out.println(sum(L)); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the above approach ` ` ` `# Function to find sum of numbers at ` `# Lth level in Pascals Triangle ` `def` `summ(h): ` ` ` `return` `pow` `(` `2` `, h ` `-` `1` `) ` ` ` `# Driver Code ` `L ` `=` `3` ` ` `print` `(summ(L)) ` ` ` `# This code is contributed by mohit kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find sum of numbers at ` ` ` `// Lth level in Pascals Triangle ` ` ` `static` `int` `sum(` `int` `h) ` ` ` `{ ` ` ` `return` `(` `int` `)Math.Pow(2, h - 1); ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `int` `L = 3; ` ` ` ` ` `Console.WriteLine(sum(L)); ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

**Output:**

4

**Time Complexity:** O(1)

## Recommended Posts:

- Sum of all the numbers present at given level in Modified Pascal’s triangle
- Maximum of all the integers in the given level of Pascal triangle
- Sum of all palindrome numbers present in an Array
- Sum of all mersenne numbers present in an array
- Sum of all perfect numbers present in an array
- Sum of all the numbers in the Nth row of the given triangle
- Triangle of numbers arising from Gilbreath's conjecture
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Probability of a key K present in array
- Count of Subsets of a given Set with element X present in it
- Sum of element whose prime factors are present in array
- Find if the given number is present in the infinite sequence or not
- Count pairs with average present in the same array
- Choose two elements from the given array such that their sum is not present in any of the arrays

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.