Find nth term of the series 3, 8, 15, 24, . . .
Last Updated :
20 Aug, 2022
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++
#include <iostream>
using namespace std;
int find_nth_Term( int n)
{
return n * (n + 2);
}
int main()
{
int N = 5;
cout << find_nth_Term(N) << endl;
return 0;
}
|
Java
class GFG
{
static int find_nth_Term( int n) { return n * (n + 2 ); }
public static void main(String args[])
{
int N = 5 ;
System.out.println(find_nth_Term(N));
}
}
|
Python
def find_nth_Term(n):
return n * (n + 2 )
n = 5
print (find_nth_Term(n))
|
C#
using System;
class GFG
{
static int find_nth_Term( int n) { return n * (n + 2); }
public static int Main()
{
int N = 5;
Console.WriteLine(find_nth_Term(N));
return 0;
}
}
|
Javascript
<script>
function find_nth_Term(n) {
return n * (n + 2);
}
let N = 5;
document.write(find_nth_Term(N) + '<br>' );
</script>
|
Time Complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1) , since no extra space has been taken.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...