Take n as input from the user. Calculate the sum of the following series up to n-th term using a recursive function.2*3*4 + 4*5*3 + 8*7*2 + 16*9*1 + ⋯
Sample input
3
Sample output:
24+60+112=196
Sample input:
6
Sample output :
24+60+112+144+0+(-832)=-492
#include <iostream>
#include <cmath>
using namespace std;
int recursiveFunction(int n)
{
// use of loop to calculate
// sum of each term
int a=2,b=3,c=4,S = 0;
for (int i = 1; i <= n; i++)
S += pow(a, i)*(2*i+b)*(c-i);
return S;
}
int main()
{
int n;
cout<<" Input The nth Term: "<<endl;
cin>>n;
cout << "The sum of n term is: "
<< recursiveFunction(n) << endl;
return 0;
}
Comments
Leave a comment