- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 given series 0, 0, 2, 1, 4, 2, 6, 3, 8, 4… in C++
In this problem, we are given an integer value N. Our task is to Find the nth term of the given series −
0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18, 9, 20, 10…
Let’s take an example to understand the problem,
Input − N = 6 Output − 2
Solution Approach
To find the Nth term of the series, we need to closely observe the series. It is the mixture of two series and odd and even terms of the series. Let’s see each of them,
At even positions −
- T(2) = 0
- T(4) = 1
- T(6) = 2
- T(8) = 3
- T(10) = 4
The value at T(n) if n is even is {(n/2) - 1}
At Odd positions −
- T(1) = 0
- T(3) = 2
- T(5) = 4
- T(7) = 6
- T(9) = 4
The value at T(n) if n is even is {n - 1}
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 findNthTerm(int n){ if (isEven(n)) return ((n/ 2) - 1); else return (n - 1); } int main(){ int N = 45; cout<<N<<"th term of the series is "<<findNthTerm(N); return 0; }
Output
45th term of the series is 44
- Related Articles
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- C++ program to find Nth term of the series 0, 2, 4, 8, 12, 18…
- C++ program to find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 …
- 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.
- Sum of the series 2 + (2+4) + (2+4+6) + (2+4+6+8) + ... + (2+4+6+8+...+2n) in C++
- Find the number from each of the following expanded forms:$(a)$. $8times10^4+6times10^3+0times10^2+4times10^1+5times10^0$$(b)$. $4times10^4+5times10^3+3times10^2+2times10^0$$(c)$. $3times10^4+7times10^2+5times10^0$$(d)$. $9times10^5+2times10^2+3times10^1$
- C++ program to get the Sum of series: 1 – x^2/2! + x^4/4! -…. upto nth term
- C++ program to Find Nth term of the series 1, 1, 2, 6, 24…
- Find the nth term of the series 0, 8, 64, 216, 512,... in C++
- Name the type of quadrilateral formed, if any, by the following points, and give reasons for your answer.(i) $(-1, -2), (1, 0), (-1, 2), (-3, 0)$(ii) $(-3, 5), (3, 1), (0, 3), (-1, -4)$(iii) $(4, 5), (7, 6), (4, 3), (1, 2)$
- Find the value of:$left( 3^{0} + 4^{-1}right) times 2^{2}$
- Find the value of ( left(3^{-1}+4^{2}+5^{-2}right)^{0} ).
- Simplify the following:$3^0 + (-4)^{-1} times 2^2$.
- Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4

Advertisements