C++ program to find n-th term of series 3, 9, 21, 41, 71…
In this problem, we are given an integer N. The task is to find the n-th term in series 3, 9, 21, 41, 71...
Let’s take an example to understand the problem,
Input
N = 7
Output
169
Explanation
The series is 3, 9, 21, 41, 71, 169...
Solution Approach
A simple solution to the problem is by finding the general term of the series.
The general term can be found by observing the series a bit. It is,
$$T(N) = \sum n^{2} + \sum n + 1$$
We can directly use the formula for the sum of square of first n natural numbers, first n natural number and then add the three values. At last return the resultant value,
$$T(N)=\left(\frac{n*(n+1)*(2n+1)}{6}\right)+\left(\frac{n*(n+1)}{2}\right)+1$$
Program to illustrate the working of our solution,
Example
Live Demo
#include <iostream>
using namespace std;
int findNthTerm(int n) {
return ((((n)*(n + 1)*(2*n + 1)) / 6) + (n * (n + 1) / 2) + 1);
}
int main() {
int N = 12;
cout<<"The "<<N<<"th term of the series is "<<findNthTerm(N);
return 0;
}
Output
The 12th term of the series is 729
Published on 13-Mar-2021 12:25:00
- Related Questions & Answers
- Program to find N-th term of series 3 , 5 , 21 , 51 , 95 , … 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++
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- C++ program to find n-th term in the series 9, 33, 73,129 …
- Program to find N-th term of series 3, 6, 18, 24, … in C++
- Program to find N-th term of series 9, 23, 45, 75, 113… 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 2, 4, 3, 4, 15… in C++
- Program to find N-th term of series 3, 12, 29, 54, 87, … in C++
- Program to find N-th term of series 0, 9, 22, 39, 60, 85, 114, 147, …in C++
- Program to find N-th term of series 3, 12, 29, 54, 86, 128, 177, 234, ….. in C++
- C++ program to find n-th term of series 2, 10, 30, 68, 130 …
- C++ program to find n-th term in the series 7, 15, 32, …
- C++ program to find Nth term of the series 5, 13, 25, 41, 61…