- Related Questions & Answers
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- Program to find sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2) in C++
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + + (1+3+5+7+....+(2n-1)) in C++
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + ...... + (1+3+5+7+...+(2n-1)) in C++
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++
- C++ program to find the sum of the series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + … + (n*n)
- Program to find N-th term of series 1, 3, 12, 60, 360...in C++
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n - 1)^2 in C++
- Sum of the Series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + ... in C++\n
- Program to find N-th term of series 3, 5, 33, 35, 53… in C++
- Program to find N-th term of series 3 , 5 , 21 , 51 , 95 , … in C++
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++

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

In this problem, we are given a number N. Our task is to create a Program to find N-th term of series 0, 2, 1, 3, 1, 5, 2, 7, 3...in C++.

**Problem Description** − We are given the Series −

**0, 2, 1, 3, 1, 5, 2, 7, 3...N Term**

To find the Nth term of this series, we will formula the general term of the series and then find the Nth term.

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

**Input** − N = 7

**Output** − 2

To solve the problem and find the general formula for the series. We need to closely observe the series as it has two different series inside it. This type of series is a bit confusing at the start but once you know that it’s a mixture series, you will find it easy to find the general term.

Here, there are two series’ one on even index and the other on the odd index. Let’s see them individually.

Even index series: 0, 1, 1, 2, 3, ….

Odd index series: 2, 3, 5, 7, …

Now, it must be clear to you that the even series is the Fibonacci series. And the odd series is a series of prime numbers.

So, the series is −

**If N is odd, (N/2) index fibonacci series.**

**If N is Even, (N/2) index prime number.**

#include<iostream> using namespace std; int findNthPrimeTerm(int n) { int primeCount = 0; for (int i = 2; ; i++) { int isPrime = 1; for (int j = 2; j <= (i/2); j++) { if (i % j == 0) { isPrime = 0; break; } } if (isPrime) primeCount++; if (primeCount == n) { return i; break; } } return -1; } int FibonaciiNthTerm(int n) { int nthTerm = 1, last = 0; int i; if( n == 0) return 0; else if( n == 1) return 1; else{ for (i = 2; i <= n; i++) { nthTerm += last; last = nthTerm - last ; } return nthTerm; } } int findNTerm(int N) { if (N % 2 == 0) return findNthPrimeTerm(N/2); else { return FibonaciiNthTerm(N/2); } } int main() { int N = 13; cout<<N<<"th term of the series is "<<findNTerm(N)<<endl; N = 4; cout<<N<<"th term of the series is "<<findNTerm(N); return 0; }

13th term of the series is 8 4th term of the series is 3

Advertisements