- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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 nth term of a given recurrence relation in C++

## Concept

Assume bn be a sequence of numbers, which is denoted by the recurrence relation b_{1}=1 and
b_{n+1}/b_{n}=2^{n}. Our task is to determine the value of log_{2}(b_{n}) for a given n.

## Input

6

## Output

15

## Explanation

log_{2}(b_{n}) = (n * (n - 1)) / 2
= (6*(6-1))/2
= 15

## Input

200

## Output

19900

## Method

b_{n+1}/b_{n} = 2^{n}

b_{n}/b_{n-1} = 2^{n-1}

.

.

.

b_{2}/b_{1} = 2^{1}, We multiply all of above in order to attain

(b_{n+1}/b_{n}).(b_{n}/_{n-1})……(b_{2}/b_{1}) = 2^{n + (n-1)+……….+1}

So, b_{n+1}/b_{1} = 2^{n(n+1)/2}

Because we know, 1 + 2 + 3 + ………. + (n-1) + n = n(n+1)/2

So, b_{n+1} = 2^{n(n+1)/2} . b_{1}; Assume the initial value b_{1} = 1

So, b_{n+1} = 2sup>n(n+1)/2

Now substituting (n+1) for n, we get,

b_{n} = 2^{n(n-1)/2}

Taking log both sides, we get,

log_{2}(b_{n}) = n(n-1)/2

## Example

// C++ program to find nth term of // a given recurrence relation #include <bits/stdc++.h> using namespace std; // Shows function to return required value int sum(int n1){ // Now get the answer int ans1 = (n1 * (n1 - 1)) / 2; //Now return the answer return ans1; } // Driver program int main(){ // Get the value of n // int n = 6; int n = 200; // Uses function call to print result cout << sum(n); return 0; }

## Output

19900

- Related Questions & Answers
- Find nth term of a given recurrence relation in Python
- C program to find nth term of given recurrence relation
- Find Pth term of a GP if Mth and Nth terms are given in C++
- Find Nth term (A matrix exponentiation example) in C++
- Find nth term of the Dragon Curve Sequence in C++
- Program to find nth Fibonacci term in Python
- C++ Program to Compute Combinations using Recurrence Relation for nCr
- JavaScript code to find nth term of a series - Arithmetic Progression (AP)
- Program to find Nth term divisible by a or b in C++
- Find the Nth term of the series 9, 45, 243,1377…in C++
- Program to find nth term of a sequence which are divisible by a, b, c in Python
- C++ program to find nth term of the series 5, 2, 13 41,...
- Find the nth term of the series 0, 8, 64, 216, 512,... in C++
- Program to find nth term in Look and Say Sequence in Python
- Program to find Fibonacci series results up to nth term in Python

Advertisements