C++ program to find n-th term in the series 7, 15, 32, …
In this problem, we are given an integer N. The task is to find n-th term in
series 7, 15, 32....
Let’s take an example to understand the problem,
Input
N = 6
Output
281
Explanation
The series upto nth term is 7, 15, 32, 67, 138, 281
Solution Approach
The solution to the problem lies in decoding the series. You can see the series is a mix of series.
The subtracting the values,
T(2) - T(1) = 15 - 7 = 8
T(3) - T(2) = 32 - 15 = 17
So, T(2) = 2*T(1) + 1
T(3) = 2*T(2) + 2
T(n) = 2*T(n-1) + (n-1)
So, the value of the nth term is found using the last term. To find these we
will loop from 1 to n and find each value of the series.
Program to illustrate the working of our solution,
Example
Live Demo
#include <iostream>
using namespace std;
int findNthTerm(int n) {
if (n == 1)
return 7;
int termN = 7;
for (int i = 2; i <= n; i++)
termN = 2*termN + (i - 1);
return termN;
}
int main(){
int n = 12;
cout<<"The series is 7, 15, 32, 67...\n";
cout<<n<<"th term of the series is "<<findNthTerm(n);
return 0;
}
Output
The series is 7, 15, 32, 67...
12th term of the series is 18419
Published on 13-Mar-2021 12:15:49
- Related Questions & Answers
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++
- C++ program to find n-th term of series 1, 3, 6, 10, 15, 21…
- Program to find N-th term of series 7, 21, 49, 91, 147, 217, …… in C++
- C++ program to find n-th term in the series 9, 33, 73,129 …
- C++ program to find Nth term of the series 1, 5, 32, 288 …
- Program to find N-th term of series 3, 6, 18, 24, … in C++
- C++ program to find n-th term of series 3, 9, 21, 41, 71…
- C++ program to find n-th term of series 2, 10, 30, 68, 130 …
- Program to find N-th term of series a, b, b, c, c, c…in C++
- n-th term of series 1, 17, 98, 354…… in C++
- Program to find N-th term of series 1 4 15 24 45 60 92... in C++
- Program to find N-th term in the given series in C++
- Program to find N-th term of series 3, 5, 33, 35, 53… in C++
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- Program to find N-th term of series 3 , 5 , 21 , 51 , 95 , … in C++