Program to find N-th term of series 3, 12, 29, 54, 87, … in C++

C++Server Side ProgrammingProgramming

In this problem, we are given a number N. Our task is to create a program to find N-th term of series 3, 12, 29, 54, 87, … in C++.

The series is

3, 12, 29, 54, 87, 128, .... N-Terms

Let’s take an example to understand the problem,

Input − N = 5

Output − 87

Solution Approach:

Let’s deduce the general term of the given series. The series is −

3, 12, 29, 54, 87, 128, ....

The general term of this series is

Tn = 4(n2 ) - 3*n + 2

Using the general term formula, we can find any value of the series.

For example,

T8 = 4*(82 ) - 3*8 + 2
T8 = 234

Example

 Live Demo

#include <iostream>
using namespace std;
int findNTerm(int N) {
   int nthTerm = ( (4*N*N) - (3*N) + 2 );
   return nthTerm;
}
int main() {
   int N = 7;
   cout<<N<<"th term of the series is "<<findNTerm(N);
   return 0;
}

Output:

7th term of the series is 177
raja
Published on 15-May-2020 16:49:17
Advertisements