Program to find N-th term of series 4, 14, 28, 46, 68, 94, 124, 158, …..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 4, 14, 28, 46, 68, 94, 124, 158, …..in C++.

Problem Description − To find the Nth term of series

4, 14, 28, 46, 68, 94, 124, … (N-terms), 

We will find the general term of the series and calculate the value based on the value of n.

Let’s take an example to understand the problem,

Input − N = 5

Output − 68

Solution Approach:

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

4, 14, 28, 46, 68, 94, 124….

We have 2 in common for all elements.

Series: 2(2, 7, 14, 23, 34, ….)
= 2((12 + 1), (22 + 3), (32 + 5), (42 + 7), (52 + 9) ….)
= 2((12 + (2-1)), (22 + (4-1)), (32 + (6-1)), (42 + (8-1)), (52 + (10-1)) ….)
= 2((12 + ((2*1)-1)), (22 + ((2*2)-1)), (32 + ((2*3)-1)), (42 + ((2*4)-1)), (52 +((2*5)-1)) ….)

The general term of the series can be generalized as −

Tn = 2*(n2 + (2*n-1))

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

For example,

T6 = 2*(62 + (2*6 - 1))
   = 2*(36 + (12 -1 ))
   = 2*(36 + 11) = 2*(47)
   = 94

Example

 Live Demo

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

Output:

11th term of the series is 284
raja
Published on 15-May-2020 13:21:12
Advertisements