- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find the Nth term of the series 14, 28, 20, 40,….. using C++

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

*14, 28, 20, 40, 32, 64, 56, 112….*

**Let’s take an example to understand the problem,**

**Input**

N = 6

**Output**

64

## Solution Approach

To find the Nth term of the series we need to find the general term of the series. For which we need to observe the series closely. I can see two different ways to solve the series.

## Method 1

The series is a mixture of two different series at even and odd positions.

**At odd positions** − 14, 20, 32, 56, ….

T_{1}= 14 T_{3}= 20 = T_{1}+ 6 T_{5}= 32 = T_{3}+ 12 T_{7}= 56 = T_{5}+ 24 = T_{1}+ 6 + 12 + 24 = T_{1}+ 6*(1 + 2 + 4) T_{N}= T_{1}+ 6(2^{0}+ 2^{1}+ 2^{2}+....+ 2^{((N/2) - 1 )})

**At even positions** − 28, 40, 64, 112…

T_{2}= 28 T_{4}= 40 = T_{2}+ 12 T_{6}= 64 = T_{4}+ 24 T_{8}= 112 = T_{6}+ 48 = T_{2}+ 12 + 24 + 48 = T_{2}+ 6*(2 + 4 + 8) T_{N}= T_{2}+ 6(2^{1}+ 2^{2}+....+ 2^{((N/2) - 1 )})

The Nth term of the series is

$\mathrm{T_{N}\, =\, T_{s}\, +\, 6\left ( \sum 2^{\left ( \left ( N/2 \right )-1 \right )} \right )}$ ,where value are from s to N incremented by 2.

For even values s = 2,

For odd values s = 1.

## Example

#include <iostream> #include <math.h> using namespace std; long findNthAdd(int s, int i, int n){ int sum = 0; for(; i <= n; i+= 2){ sum += pow(2, (int)((i/2) - 1)); } return 6*sum; } long findNthTermSeries(int n){ int s, i; if(n % 2 == 0){ s = 28; i = 4; } else{ s = 14; i = 3; } return ( s + findNthAdd(s, i, n)); } int main(){ int n = 15; cout<<n<<"th term of the series is "<<findNthTermSeries(n); return 0; }

## Output

15th term of the series is 776

## Another solution

One more way, using which the Nth term can be found is using the fact that the current term is either twice of the previous term or it 8 less from the previous term based on it’s even/odd.

If N is even T_{N}= 2*T_{(N-1)}If N is odd T_{N}= T_{(N-1)}- 8

So, we need to loop from 2 to N, and find T_{i} by checking if its even or odd.

## Example

Program to illustrate the working of our solution,

#include <iostream> using namespace std; bool isEven(int N){ if(N % 2 == 0) return true; return false; } int findNthTermSeries(int n){ int TermN = 14; for (int i = 2; i <= n; i++) { if (isEven(i)) TermN *= 2; else TermN -= 8; } return TermN; } int main(){ int n = 15; cout<<n<<"th term of the series is "<<findNthTermSeries(n); return 0; }

## Output

15th term of the series is 776

- Related Questions & Answers
- C++ program to find Nth term of the series 3, 14, 39, 84…
- C++ program to find Nth term of the series 1, 6, 18, 40, 75, ….
- Program to find N-th term of series 4, 14, 28, 46, 68, 94, 124, 158, …..in C++
- Find the Nth term of the series 9, 45, 243,1377…in C++
- C++ program to find Nth number of the series 1, 6, 15, 28, 45, …..
- Find the nth term of the series 0, 8, 64, 216, 512,... in C++
- C++ program to find nth term of the series 5, 2, 13 41,...
- C++ program to find Nth term of the series 1, 5, 32, 288 …
- C++ program to find Nth term of the series 1, 8, 54, 384…
- C++ program to Find Nth term of the series 1, 1, 2, 6, 24…
- C++ program to find Nth term of the series 5, 13, 25, 41, 61…
- JavaScript code to find nth term of a series - Arithmetic Progression (AP)
- Find nth term of the Dragon Curve Sequence in C++
- C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18…
- Find the Nth term of the series where each term f[i] = f[i – 1] – f[i – 2] in C++