
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Program to find N-th term of series 2, 4, 3, 4, 15… 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 2, 4, 3, 4, 15… in C++.
Problem Description − To find the sum of the given series,
2, 4, 3, 4, 15, 0, 14, 16 .... N terms
We will find the formula for the general term of the series.
Let’s take an example to understand the problem,
Input − N = 9
Output − 9
Solution Approach:
The increase of the values in the series is linear i.e. no square values are in the series. Also, it’s value depends on other factors too (division by 2 and 3, as 6 gives 0).
So, we will first take out N (i.e. 1, 2, 3) from their value from the series.
Series: 1*(2), 2*(2), 3*(1), 4*(1), 5*(3), 6*(0), …
On observing this we can deduct the general formula is −
Tn = ( N*((N%2)+(N%3)) )
Program to show the implementation of our solution,
#include <iostream> using namespace std; int findNTerm(int N) { int nthTerm = ( N*((N%2) + (N%3)) ); return nthTerm; } int main() { int N = 10; cout<<N<<"th term of the series is "<<findNTerm(N); return 0; }
Output:
10th term of the series is 10
- Related Articles
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- 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 4 15 24 45 60 92... in C++
- C++ program to find n-th term of series 1, 3, 6, 10, 15, 21…
- C++ program to find n-th term in the series 7, 15, 32, …
- C++ program to find n-th term of series 1, 4, 27, 16, 125, 36, 343...
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++
- Program to find N-th term of series 3, 6, 18, 24, … in C++
- Program to find N-th term of series 4, 14, 28, 46, 68, 94, 124, 158, …..in C++
- C++ program to find n-th term of series 3, 9, 21, 41, 71…
- C++ program to find Nth term of series 1, 4, 15, 72, 420…
- Program to find N-th term of series 3, 5, 33, 35, 53… in C++
- Program to find N-th term of series 1, 3, 12, 60, 360...in C++

Advertisements