Program to find N-th term of series 3 , 5 , 21 , 51 , 95 , … in C++

C++Server Side ProgrammingProgramming

In this problem, we are given a number N. Our task is to create a Program to find N-th term of series 3 , 5 , 21 , 51 , 95 , … in C++.

Problem Description − To find the Nth terms of the series −

3, 5, 21, 51, 95, 153, … N-Terms

We need to find the general formula of the series, which is a quadratic equation (based increase in the series).

Let’s take an example to understand the problem,

Input − N = 6

Output − 153

Solution Approach:

To solve the problem, we will find the general formula for the nth term of the series which is given by −

Tn = 7*(n^2) - 19*n + 15

Example

 Live Demo

#include <iostream>
using namespace std;
int findNTerm(int N) {
   int nthTerm = ( (7*(N*N)) - (19*N) + 15 );
   return nthTerm;
}
int main() {
   int N = 7;
   cout<<N<<"th term of the series is "<<findNTerm(N);
   return 0;
}

Output:

7th term of the series is 225
raja
Published on 15-May-2020 13:13:24
Advertisements