- 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

# C++ program to find n-th term of series 3, 9, 21, 41, 71â€¦

In this problem, we are given an integer N. The task is to find the n-th term in series 3, 9, 21, 41, 71...

**Let’s take an example to understand the problem,**

## Input

N = 7

## Output

169

## Explanation

The series is 3, 9, 21, 41, 71, 169...

## Solution Approach

A simple solution to the problem is by finding the general term of the series. The general term can be found by observing the series a bit. It is,

$$T(N) = \sum n^{2} + \sum n + 1$$

We can directly use the formula for the sum of square of first n natural numbers, first n natural number and then add the three values. At last return the resultant value,

$$T(N)=\left(\frac{n*(n+1)*(2n+1)}{6}\right)+\left(\frac{n*(n+1)}{2}\right)+1$$

**Program to illustrate the working of our solution,**

## Example

#include <iostream> using namespace std; int findNthTerm(int n) { return ((((n)*(n + 1)*(2*n + 1)) / 6) + (n * (n + 1) / 2) + 1); } int main() { int N = 12; cout<<"The "<<N<<"th term of the series is "<<findNthTerm(N); return 0; }

## Output

The 12th term of the series is 729

- Related Articles
- C++ program to find n-th term of series 1, 3, 6, 10, 15, 21â€¦
- Program to find N-th term of series 3 , 5 , 21 , 51 , 95 , â€¦ in C++
- Program to find N-th term of series 1, 2, 11, 12, 21â€¦ in C++
- C++ program to find n-th term in the series 9, 33, 73,129 â€¦
- Program to find N-th term of series 7, 21, 49, 91, 147, 217, â€¦â€¦ in C++
- Program to find N-th term of series 9, 23, 45, 75, 113â€¦ in C++
- Program to find N-th term of series 3, 6, 18, 24, â€¦ in C++
- 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++
- Program to find N-th term of series 2, 4, 3, 4, 15â€¦ in C++
- Program to find N-th term of series 3, 12, 29, 54, 87, â€¦ in C++
- 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 in the given series in C++
- Program to find N-th term of series 0, 9, 22, 39, 60, 85, 114, 147, â€¦in C++
- C Program for N-th term of Geometric Progression series

Advertisements