Answer to Question #272422 in C++ for Danial

Question #272422


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


1
Expert's answer
2021-11-27T11:37:19-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS