Program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2) in C++

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2)

For this we will be provided with the value of n. Our task is to calculate the sum of the series upto the given value and print it out.

Example

Live Demo

#include <bits/stdc++.h>
using namespace std;
//calculating sum of series
int sumOfSeries(int n) {
int sum = 0;
for (int i = 1; i <= n; i++)
sum = sum + i * (i + 1) * (i + 2);
return sum;
}
int main() {
int n = 10;
cout << sumOfSeries(n);
return 0;
}

Output

4290
Published on 27-May-2020 13:17:13