- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# 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 Articles
- 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, â€¦.
- 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, â€¦..
- 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 0, 8, 64, 216, 512,... in C++
- 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 5, 2, 13 41,...
- 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â€¦
- Find the sum of first 20 terms of the sequence whose nth term is $a_n = An + B$.
- Find the Nth term of the series where each term f[i] = f[i â€“ 1] â€“ f[i â€“ 2] in C++
- C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18â€¦
- JavaScript code to find nth term of a series - Arithmetic Progression (AP)