Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmFind nth term of the series 3, 8, 15, 24, . ....

Find nth term of the series 3, 8, 15, 24, . . .

Given an integer N, the task is to find the Nth term of the series 

3, 8, 15, 24, . . .till Nth term

Examples:

Input: N = 5 
Output: 35

Input: N = 6
Output: 48

Approach:

From the given series, find the formula for the Nth term

1st term  = 1 (1 + 2) = 3

2nd term = 2 (2 + 2) = 8

3rd term =  3 (3 + 2) = 15

4th term =  4 (4 + 2) = 24

.

.

Nth term = N * (N + 2) 

The Nth term of the given series can be generalized as-

TN = N * (N + 2)

Illustration:

Input: N = 5
Output: 35
Explanation:
TN = N * (N + 2)
     = 5 * (5 + 2)
     = 35

Below is the implementation of the above approach-

C++




// C++ program to find nth term
// of the series
#include <iostream>
using namespace std;
 
// Function to return nth term
// of the series
int find_nth_Term(int n)
{
    return n * (n + 2);
}
 
// Driver code
int main()
{
    // Find given nth term
    int N = 5;
 
    // Function call
    cout << find_nth_Term(N) << endl;
    return 0;
}


Java




// Java program to find nth term
// of the series
class GFG
{
 
  // Function to return nth term
  // of the series
  static int find_nth_Term(int n) { return n * (n + 2); }
 
  // Driver code
  public static void main(String args[])
  {
 
    // Find given nth term
    int N = 5;
 
    // Function call
    System.out.println(find_nth_Term(N));
  }
}
 
// This code is contributed by gfgking


Python




# Python program to find nth
# term of the series
 
# Function to return nth
# term of the series
def find_nth_Term(n):
 
    return n * (n + 2)
 
 
# Driver code
 
# Find given nth term
n = 5
 
# Function call
print(find_nth_Term(n))
 
# This code is contributed by Samim Hossain Mondal.


C#




// C# program to find nth term
// of the series
using System;
class GFG
{
 
  // Function to return nth term
  // of the series
  static int find_nth_Term(int n) { return n * (n + 2); }
 
  // Driver code
  public static int Main()
  {
 
    // Find given nth term
    int N = 5;
 
    // Function call
    Console.WriteLine(find_nth_Term(N));
    return 0;
  }
}
 
// This code is contributed by Taranpreet


Javascript




<script>
       // JavaScript code for the above approach
 
       // Function to return nth term
       // of the series
       function find_nth_Term(n) {
           return n * (n + 2);
       }
 
       // Driver code
 
       // Find given nth term
       let N = 5;
 
       // Function call
       document.write(find_nth_Term(N) + '<br>');
 
      // This code is contributed by Potta Lokesh
   </script>


Output

35

Time Complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1) , since no extra space has been taken.

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Last Updated :
20 Aug, 2022
Like Article
Save Article


Previous

<!–

8 Min Read | Java

–>


Next


<!–

8 Min Read | Java

–>

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments