Number Series 3

Description:

Write a program to Calculate (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) series Test Case 1 Input (stdin) 10 Expected Output 220 Test Case 2 Input (stdin) 9 Expected Output 165

Program :

#include <bits/stdc++.h> 
using namespace std; 

// Function to find sum of given series 
int sumOfSeries(int n) 
{ 
 int sum = 0; 
 for (int i = 1 ; i <= n ; i++) 
  for (int j = 1 ; j <= i ; j++) 
   sum += j; 
 return sum; 
} 

// Driver Function 
int main() 
{ 
 int n ; 
  cin>>n;
 cout << sumOfSeries(n); 
 return 0; 
}