Given the value of n, we need to find the sum of the series where i-th term is sum of first i natural numbers.
NOTE: Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + …… + (1+2+3+4+…+n)
Input: n = 5 Output: 35 Explanation: 1 + (1+2) + (1+2+3).. = 35 Hence sum of the series is 35.
Input: n = 10 Output: 210 Explanation: 1 + (1+2) + (1+2+3) + (1+2+3+4) + (1+2+3+4+5)... = 210. Hence sum of the series is 210.
You dont need to read input or print anything. Complete the function sumOfTheSeries() which takes n as input parameter and returns the sum of the series of n terms.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
1<= n <=1000
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.