- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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,
T8 = 4*(82 ) - 3*8 + 2 T8 = 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
To Continue Learning Please Login
Login with Google