Skip to content
Related Articles

Related Articles

Improve Article

Program to find Nth term of series 9, 23, 45, 75, 113…

  • Difficulty Level : Medium
  • Last Updated : 15 Mar, 2021

Given a number N, the task is to find the Nth term in the given series: 
 

9, 23, 45, 75, 113, 159......

Examples: 
 

Input: 4
Output: 113
Explanation:
For N = 4
Nth term = ( 2 * N + 3 )*( 2 * N + 3 ) - 2 * N
         = ( 2 * 4 + 3 )*( 2 * 4 + 3 ) - 2 * 4
         = 113

Input: 10
Output: 509

 

Approach: 
The Nth term of the given series can be generalised as: 
 

Nth term of the series : ( 2 * N + 3 )*( 2 * N + 3 ) - 2 * N

Below is the implementation of the above problem:
Program: 
 



C++




// CPP program to find N-th term of the series:
// 9, 23, 45, 75, 113...
 
#include <iostream>
using namespace std;
 
// calculate Nth term of series
int nthTerm(int N)
{
    return (2 * N + 3) * (2 * N + 3) - 2 * N;
}
 
// Driver Function
int main()
{
 
    // Get the value of N
    int N = 4;
 
    // Find the Nth term
    // and print it
    cout << nthTerm(N);
 
    return 0;
}

Java




// Java program to find
// N-th term of the series:
// 9, 23, 45, 75, 113...
 
class GFG
{
 
// calculate Nth term of series
static int nthTerm(int N)
{
    return (2 * N + 3) *
           (2 * N + 3) - 2 * N;
}
 
// Driver code
public static void main(String[] args)
{
     
    // Get the value of N
    int N = 4;
     
    // Find the Nth term
    // and print it
    System.out.println(nthTerm(N));
}
}
 
// This code is contributed by Bilal

Python3




# Python program to find
# N-th term of the series:
# 9, 23, 45, 75, 113...
def nthTerm(N):
     
    # calculate Nth term of series
    return ((2 * N + 3) *
            (2 * N + 3) - 2 * N);
 
# Driver Code
 
# Get the value of N
n = 4
 
# Find the Nth term
# and print it
print(nthTerm(n))
 
# This code is contributed by Bilal

C#




// C# program to find
// N-th term of the series:
// 9, 23, 45, 75, 113...
using System;
 
class GFG
{
 
// calculate Nth term of series
static int nthTerm(int N)
{
    return (2 * N + 3) *
           (2 * N + 3) - 2 * N;
}
 
// Driver code
public static void Main()
{
     
    // Get the value of N
    int N = 4;
     
    // Find the Nth term
    // and print it
    Console.WriteLine(nthTerm(N));
}
}
 
// This code is contributed
// by Akanksha Rai(Abby_akku)

PHP




<?php
// PHP program to find
// N-th term of the series:
// 9, 23, 45, 75, 113...
 
// calculate Nth term of series
function nthTerm($N)
{
    return (2 * $N + 3) *
           (2 * $N + 3) - 2 * $N;
}
 
// Driver Code
 
// Get the value of N
$N = 4;
 
// Find the Nth term
// and print it
echo nthTerm($N);
 
// This code is contributed by Raj
?>

Javascript




<script>
 
// JavaScript program to find N-th term of the series:
// 9, 23, 45, 75, 113...
 
// calculate Nth term of series
function nthTerm( N)
{
    return (2 * N + 3) * (2 * N + 3) - 2 * N;
}
// Driver Function
 
    // get the value of N
    let N = 4;
 
    // Calculate and print the Nth term
    document.write(  nthTerm(N));
 
// This code is contributed by todaysgaurav
 
</script>
Output: 
113

 

Time Complexity: O(1)
 

Attention reader! Don’t stop learning now. Participate in the Scholorship Test for First-Step-to-DSA Course for Class 9 to 12 students.




My Personal Notes arrow_drop_up
Recommended Articles
Page :