Find the Nth term of the series 9, 45, 243,1377…in C++

C++Server Side ProgrammingProgramming

In this problem, we are given an integer value N.Our task is to Find the nth term of the series −

9, 45, 243, 1377, 8019, …

Let’s take an example to understand the problem,

Input : N = 4
Output : 1377

Solution Approach

A simple solution to find the problem is by finding the Nth term using observation technique. On observing the series, we can formulate as follow −

(11 + 21)*31 + (12 + 22)*32 + (13 + 23)*33 … + (1n + 2n)*3n

Example

Program to illustrate the working of our solution

#include <iostream>
#include <math.h>
using namespace std;
long findNthTermSeries(int n){
   return ( ( (pow(1, n) + pow(2, n)) )*pow(3, n) );
}
int main(){
   int n = 4;
   cout<<n<<"th term of the series is "<<findNthTermSeries(n);
   return 0;
}

Output

4th term of the series is 1377
raja
Updated on 24-Jan-2022 12:18:13

Advertisements