# Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + – – – – – – upto n terms.

Given a positive integer n, find the sum of the series upto n terms.

Examples :

```Input : n = 4
Output : 3.91667
Series : (1 / 1) + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + (1 + 2 + 3 + 4) / (1 * 2 * 3 * 4)
= 1 / 1 + 3 / 2 + 6 / 6 + 10 / 24
= 3.91667

Input : n = 6
Output : 4.07083
Series : (1 / 1) + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3)  + (1 + 2 + 3 + 4) / (1 * 2 * 3 * 4) + (1 + 2 + 3 + 4 + 5) / (1 * 2 * 3 * 4 * 5)  + (1 + 2 + 3 + 4 + 5 + 6) / (1 * 2 * 3 * 4 * 5 * 6)
= 1 / 1 + 3 / 2 + 6 / 6 + 10 / 24 + 15 / 120 + 21 / 720
= 4.07083
```

## C++

 `// CPP program to find sum of series. ` `#include ` `using` `namespace` `std; ` ` `  `double` `sumOfSeries(``int` `n) ` `{ ` `    ``double` `res = 0.0 ; ` `    ``int` `sum = 0, prod = 1; ` `    ``for` `(``int` `i = 1 ; i <= n ; i++) ` `    ``{ ` `        ``sum += i; ` `        ``prod *= i; ` `        ``res += ((``double``)sum / prod); ` `    ``} ` `    ``return` `res; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``int` `n = 4 ; ` `    ``cout << sumOfSeries(n) ;     ` `    ``return` `0; ` `} `

## Java

 `// Java program to find sum of series. ` `class` `GFG  ` `{ ` `static` `double` `sumOfSeries(``int` `n)  ` `{ ` `    ``double` `res = ``0.0``; ` `    ``int` `sum = ``0``, prod = ``1``; ` `    ``for` `(``int` `i = ``1``; i <= n; i++) { ` `    ``sum += i; ` `    ``prod *= i; ` `    ``res += ((``double``)sum / prod); ` `    ``} ` `    ``return` `res; ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String arg[]) { ` `    ``int` `n = ``4``; ` `    ``System.out.println(sumOfSeries(n)); ` `} ` `} ` ` `  `// This code is contributed by Anant Agarwal. `

## Python3

 `# Python program to ` `# find sum of series. ` ` `  `def` `sumOfSeries(n) : ` ` `  `    ``res ``=` `0.0` `    ``sum` `=` `0` `    ``prod ``=` `1` `    ``for` `i ``in` `range``(``1``, n ``+` `1``) : ` `     `  `        ``sum` `=` `sum` `+` `i ` `        ``prod ``=` `prod ``*` `i ` `        ``res ``=` `res ``+` `(``sum` `/` `prod) ` `         `  `    ``return` `res ` `     `  `# Driver Code ` `n ``=` `4` `print` `(``round``(sumOfSeries(n), ``5``))  ` ` `  `# This code is contributed by  ` `# Manish Shaw(manishshaw1) `

## C#

 `// C# program to find sum of series. ` `using` `System; ` ` `  `class` `GFG { ` ` `  `    ``static` `double` `sumOfSeries(``int` `n) ` `    ``{ ` `        ``double` `res = 0.0; ` `        ``int` `sum = 0, prod = 1; ` `        ``for` `(``int` `i = 1; i <= n; i++) { ` `            ``sum += i; ` `            ``prod *= i; ` `            ``res += ((``double``)sum / prod); ` `        ``} ` `        ``return` `res; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``int` `n = 4; ` `        ``Console.Write(sumOfSeries(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by vt_m. `

## PHP

 ` `

Output :

```3.91667
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Improved By : jit_t, manishshaw1

Article Tags :
Practice Tags :

Be the First to upvote.

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