
- 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
Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
In this problem, we are given a number N. Our task is to create a program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++.
Problem description
To find the Nth term of the given series−
0, 0, 2, 1, 4, 2, 6, 3, 8 .... N Terms
We will find the general term of the series.
Let’s take an example to understand the problem,
Input
N = 8
Output
3
Solution Approach
To find the general term of the series, we need to closely observe the series. This series is a bit difficult to recognize as it is a mixture of two series. One series at even positions and one series at odd positions.
Odd Series− 0, 2, 4, 6, 8, 10, 12,....
Even Series− 0, 1, 2, 3, 4, 5, 6,....
Here,
If the nth term of the series is
Odd, the value is (n-1).
Even, the value is $T_{(n-1)}/2$
Example
#include using namespace std; int findNTerm(int N) { if (N % 2 == 0) return findNTerm(N-1)/2; else { return (N-1); } } int main(){ int N = 13; cout<<N<<"th term of the series is "<<findNTerm(N)<<endl; }
Output
13th term of the series is 12
- Related Articles
- Find the nth term of the given series 0, 0, 2, 1, 4, 2, 6, 3, 8, 4… in C++
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++
- Following data gives the number of children in 41 families:$1, 2, 6, 5, 1, 5, 1, 3, 2, 6, 2, 3, 4, 2, 0, 0, 4, 4, 3, 2, 2, 0, 0, 1, 2, 2, 4, 3, 2, 1, 0, 5, 1, 2, 4, 3, 4, 1, 6, 2, 2.$Represent it in the form of a frequency distribution.
- C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18…
- Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2
- C++ program to find n-th term of series 1, 3, 6, 10, 15, 21…
- Program to find N-th term of series 0, 7, 8, 33, 51, 75, 102, 133...in C++
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- C++ program to find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 …
- Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
- Find sum of Series with n-th term as n^2 - (n-1)^2 in C++
- n-th number with digits in {0, 1, 2, 3, 4, 5} in C++
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!

Advertisements