- 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
Find the Nth term of the series 9, 45, 243,1377…in C++
In this problem, we are given an integer value N.Our task is to Find the nth term of the series −
9, 45, 243, 1377, 8019, …
Let’s take an example to understand the problem,
Input : N = 4 Output : 1377
Solution Approach
A simple solution to find the problem is by finding the Nth term using observation technique. On observing the series, we can formulate as follow −
(11 + 21)*31 + (12 + 22)*32 + (13 + 23)*33 … + (1n + 2n)*3n
Example
Program to illustrate the working of our solution
#include <iostream> #include <math.h> using namespace std; long findNthTermSeries(int n){ return ( ( (pow(1, n) + pow(2, n)) )*pow(3, n) ); } int main(){ int n = 4; cout<<n<<"th term of the series is "<<findNthTermSeries(n); return 0; }
Output
4th term of the series is 1377
Advertisements