- 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
N-th term in the series 1, 11, 55, 239, 991,…in C++
The given series is 1, 11, 55, 239, 991...
If you clearly observe the series, you will find that the n-th number is 4n-2n-1.
Algorithm
- Initialise the number N.
- Use the series formula to compute the n-th term.
- Print the result.
Implementation
Following is the implementation of the above algorithm in C++
#include <bits/stdc++.h> using namespace std; int getNthTerm(int n) { int num = pow(4, n) - pow(2, n) - 1; return num; } int main() { int n = 7; cout << getNthTerm(n) << endl; return 0; }
Output
If you run the above code, then you will get the following result.
16255
Advertisements