
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to find n-th term of series 1, 4, 27, 16, 125, 36, 343...
In this problem, we are given an integer N. The task is to find the n-th term in series 1, 4, 27, 16, 125, 36, 343....
Let’s take an example to understand the problem,
Input
N = 7
Output
343
Explanation
The series is 1,4, 27, 16, 125, 36, 343…
Solution Approach
A simple solution to the problem is by finding the general term of the series. This series comprises two different series one at odd terms and one at even terms. If the current element index is even, the element is square of its index. And if the current element index is odd, the element is the cube of its index.
Program to illustrate the working of our solution,
Example
#include <iostream> using namespace std; int findNthTerm(int N) { if (N % 2 == 0) return (N*N); return (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 64
- Related Questions & Answers
- Program to find N-th term of series 1 4 15 24 45 60 92... in C++
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Program to find N-th term of series 1, 3, 12, 60, 360...in C++
- n-th term in series 2, 12, 36, 80, 150….in C++
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- C++ program to find n-th term of series 1, 3, 6, 10, 15, 21…
- Find sum of Series with n-th term as n^2 - (n-1)^2 in C++
- Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2
- C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2
- C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2
- C Program for N-th term of Geometric Progression series
- C Program for N-th term of Arithmetic Progression series
- Program to find N-th term in the given series in C++
Advertisements