C++ Program to find the sum of the series 23+ 45+ 75+….. upto N terms


In this tutorial, we will be discussing a program to find the sum of the given series 23+ 45+ 75+….. upto N terms.

For this, we will be given with the value of N and our task is to add up every term starting from the first one to find the sum of the given series.

After solving this, we get the formula for the sum of the series;

Sn = (2n(n+1)(4n+17)+54n)/6

Example

#include <iostream>
using namespace std;
//calculating the sum of the series
int calc_sum(int N) {
   int i;
   int sum = (2 * N * (N + 1) * (4 * N + 17) + 54 * N) / 6;
   return sum;
}
int main() {
   int N = 7;
   int res = calc_sum(N);
   cout << res << endl;
   return 0;
}

Output

903

Updated on: 09-Jul-2020

136 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements