Related Articles
Find the Sum of the series 1 + 2 + 9 + 64 + 625 + 7776 … till N terms
• Last Updated : 18 Mar, 2021

Given a number N, the task is to find the sum of the below series till N terms. Examples:

Input: N = 2
Output:
1 + 2 = 3
Input: N = 5
Output: 701
1 + 2 + 9 + 64 + 625 = 701

Approach: From the given series, find the formula for Nth term:

```1st term = 1 = 11-1
2nd term = 2 = 22-1
3rd term = 9 = 33-1
4th term = 64 = 44-1
.
.
Nthe term = NN - 1```

Therefore:

Nth term of the series

```*** QuickLaTeX cannot compile formula:

*** Error message:
Error: Nothing to show, formula is empty
```

Then iterate over numbers in the range [1, N] to find all the terms using the above formula and compute their sum.
Below is the implementation of the above approach:

## C++

 `// C++ program for the above approach` `#include ``using` `namespace` `std;` `// Function to find the sum of series``void` `printSeriesSum(``int` `N)``{``    ``long` `long` `sum = 0;` `    ``for` `(``int` `i = 1; i <= N; i++) {` `        ``// Generate the ith term and``        ``// add it to the sum``        ``sum += ``pow``(i, i - 1);``    ``}` `    ``// Print the sum``    ``cout << sum << endl;``}` `// Driver Code``int` `main()``{``    ``int` `N = 5;` `    ``printSeriesSum(N);``    ``return` `0;``}`

## Java

 `// Java program for the above approach``class` `GFG{`` ` `// Function to find the sum of series``static` `void` `printSeriesSum(``int` `N)``{``    ``long` `sum = ``0``;`` ` `    ``for` `(``int` `i = ``1``; i <= N; i++) {`` ` `        ``// Generate the ith term and``        ``// add it to the sum``        ``sum += Math.pow(i, i - ``1``);``    ``}`` ` `    ``// Print the sum``    ``System.out.print(sum +``"\n"``);``}`` ` `// Driver Code``public` `static` `void` `main(String[] args)``{``    ``int` `N = ``5``;`` ` `    ``printSeriesSum(N);``}``}` `// This code is contributed by Princi Singh`

## Python3

 `# Python3 program for the above approach` `# Function to find the summ of series``def` `printSeriessumm(N):``    ``summ ``=` `0``    ` `    ``for` `i ``in` `range``(``1``,N``+``1``):``        ` `        ``# Generate the ith term and``        ``# add it to the summ``        ``summ ``+``=` `pow``(i, i ``-` `1``)``    ` `    ``# Prthe summ``    ``print``(summ)``    ` `# Driver Code` `N ``=` `5``printSeriessumm(N)` `# This code is contributed by shubhamsingh10`

## C#

 `// C# program for the above approach``using` `System;` `class` `GFG{``  ` `// Function to find the sum of series``static` `void` `printSeriesSum(``int` `N)``{``    ``double` `sum = 0;``  ` `    ``for` `(``int` `i = 1; i <= N; i++) {``  ` `        ``// Generate the ith term and``        ``// add it to the sum``        ``sum += Math.Pow(i, i - 1);``    ``}``  ` `    ``// Print the sum``    ``Console.Write(sum +``"\n"``);``}``  ` `// Driver Code``public` `static` `void` `Main(String[] args)``{``    ``int` `N = 5;``    ``printSeriesSum(N);``}``}` `// This code is contributed by PrinciRaj1992`

## Javascript

 ``
Output:
`701`

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.

My Personal Notes arrow_drop_up