- Related Questions & Answers
- C++ program to get the Sum of series: 1 – x^2/2! + x^4/4! -…. upto nth term
- C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2
- Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
- Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2
- Maximize value of (arr[i] – i) – (arr[j] – j) in an array in C++
- Maximum value of |arr[i] – arr[j] - + |i – j| in C++
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2
- Maximum value of |arr[0] – arr[1] - + |arr[1] – arr[2] - + … +|arr[n – 2] – arr[n – 1] - when elements are from 1 to n in C++
- Maximize arr[j] – arr[i] + arr[l] – arr[k], such that i < j < k < l in C++
- Find nth term of the Dragon Curve Sequence in C++
- Sum of series 2/3 – 4/5 + 6/7 – 8/9 + …… upto n terms
- Formatted string literals (f-strings) in Python?
- C# Fixed-Point (“F”) Format Specifier
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- Why is f required while declaring floats 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

Suppose we have a series called f. Each term of f, follows this rule f[i] = f[i – 1] – f[i – 2], we have to find the Nth term of this sequence. f[0] = X and f[1] = Y. If X = 2 and Y = 3, and N = 3. The result will be -2.

If we see this closely, there will be almost six terms before the sequence starts repeating itself. So we will find the first 6 terms of the series and then the Nth term will be the same as (N mod 6)th term.

#include< iostream> using namespace std; int searchNthTerm(int x, int y, int n) { int terms[6]; terms[0] = x; terms[1] = y; for (int i = 2; i < = 5; i++) terms[i] = terms[i - 1] - terms[i - 2]; return terms[n % 6]; } int main() { int x = 2, y = 3, n = 3; cout << "Term at index " < < n << " is: "<< searchNthTerm(x, y, n); }

Term at index 3 is: -2

Advertisements