Given and integer N. Calculate the sum of series 13 + 23 + 33 + 43 + … till N-th term using recursion.

 Sum of Cube of N-th term series using Recursion


Given an integer N. Calculate the sum of series 13 + 23 + 33 + 43 + … till N-th term using recursion.



Sum Of Cube of N th term


Example 1:

Input:
N=5
Output:
225
Explanation:
13+23+33+43+53=225

Example 2:
Input:
N=7
Output:
784
Explanation:
13+23+33+43+53+63+73=784

Your Task:

Your task is to print the term's sum cube using recursion. Make a function that takes a single argument and returns the adequate sum.

Expected Time Complexity: O(1)
Expected Auxillary Space: O(N)



Solution:


#include<iostream>
using namespace std;

long long sumOfSeries(long long N){

        if(N==0){
            return 0;
        }
        return (N*N*N)+sumOfSeries(N-1);
}

int main(){
    long long n;
    cout<<"Enter the N the term : ";
    cin>>n;
    cout<<"The sum of "<<n <<"th Series : "<<sumOfSeries(n);
}



Comments

Popular posts from this blog

R language Coding

INTRODUCTION TO BLOGGING