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 = 3Output:4

1 + 2 + 1 = 4Input:L = 2Output: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;` `}` |

## 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` |

## 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` |

## 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..` |

## Javascript

`<script>` `// Javascript implementation of the above approach` `// Function to find sum of numbers at` `// Lth level in Pascals Triangle` `function` `sum(h)` `{` ` ` `return` `Math.pow(2, h - 1);` `}` `// Driver Code` `var` `L = 3;` `document.write(sum(L));` `</script>` |

**Output:**

4

**Time Complexity:** O(1)

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