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
C++ program to find n-th term of series 2, 10, 30, 68, 130 ...
In this problem, we are given an integer N. The task is to find the n-th term in series 2, 10, 30, 68, 130...
Let’s take an example to understand the problem,
Input
N = 7
Output
350
Explanation
The series is 2, 10, 30, 68, 130, 222, 350...
Solution Approach
A simple solution to the problem is by finding the general term of the series. Here, the Nth term of the series is N^3 + N. This is found by subtracting the current element with the current index.
For i, i = 1, T(1) = 2 = 1 + 1 = 1^3 + 1 i = 2, T(1) = 10 = 8 + 2 = 2^3 + 2 i = 3, T(1) = 30 = 27 + 3 = 3^3 + 2
Program to illustrate the working of our solution,
Example
#include <iostream>
using namespace std;
int findNthTerm(int N) {
return ((N*N*N) + N);
}
int main() {
int N = 8;
cout<<"The "<<N<<"th term of the series is "<<findNthTerm(N);
return 0;
}
Output
The 8th term of the series is 520
Advertisements
