Sum of the first N terms of the series 5 , 12 , 23 , 38. ... | C ++ program to find sum of first n terms ; Function to calculate the sum ; Driver code ; number of terms to be included in sum ; find the Sn
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculateSum ( int n ) { return 2 * ( n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ) + n * ( n + 1 ) / 2 + 2 * ( n ) ; } int main ( ) { int n = 3 ; cout << " Sum ▁ = ▁ " << calculateSum ( n ) ; return 0 ; }