Timer is Running

Special Series Sum
Submissions: 88   Accuracy:

71.55%

  Difficulty: Basic   Marks: 1

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)

Example 1:

Input: n = 5
Output: 35 
Explanation: 1 + (1+2) + (1+2+3).. = 35
Hence sum of the series is 35.


Example 2:

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.


Your Task:  
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)

Constraints:
1<= n <=1000

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sahil Chhabra
Author: Sahil_Chhabra


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.