Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Program to find N-th term of series 3, 12, 29, 54, 87, ... in C++
In this problem, we are given a number N. Our task is to create a program to find N-th term of series 3, 12, 29, 54, 87, … in C++.
The series is
3, 12, 29, 54, 87, 128, .... N-Terms
Let’s take an example to understand the problem,
Input − N = 5
Output − 87
Solution Approach:
Let’s deduce the general term of the given series. The series is −
3, 12, 29, 54, 87, 128, ....
The general term of this series is
Tn = 4(n2 ) - 3*n + 2
Using the general term formula, we can find any value of the series.
For example,
T<sub>8</sub> = 4*(8<sup>2</sup> ) - 3*8 + 2 T<sub>8</sub> = 234
Example
#include <iostream>
using namespace std;
int findNTerm(int N) {
int nthTerm = ( (4*N*N) - (3*N) + 2 );
return nthTerm;
}
int main() {
int N = 7;
cout<<N<<"th term of the series is "<<findNTerm(N);
return 0;
}
Output:
7th term of the series is 177
Advertisements
