Find nth term of the series 2, 8, 18, 32, 50, . . . .
Last Updated :
23 Jun, 2022
Given an integer N, the task is to find the Nth term of the series
2, 8, 18, 32, 50, ….till N terms
Examples:
Input: N = 4
Output: 32
Input: N = 6
Output: 72
Approach:
From the given series, find the formula for Nth term-
1st term = 2 * 1 ^ 2 = 2
2nd term = 2 * 2 ^ 2 = 8
3rd term = 2 * 3 ^ 2 = 18
4th term = 2 * 4 ^ 2 = 32
.
.
Nth term = 2 * N ^ 2
The Nth term of the given series can be generalized as-
TN = 2 * N ^ 2
Illustration:
Input: N = 6
Output: 72
Explanation:
TN= 2 * N ^ 2
= 2 * 6 ^ 2
= 72
Below is the implementation of the above approach-
C++
#include <iostream>
using namespace std;
int find_nth_Term( int n) { return 2 * n * n; }
int main()
{
int N = 6;
cout << find_nth_Term(N) << endl;
return 0;
}
|
Java
import java.io.*;
import java.lang.*;
import java.util.*;
class GFG {
static int find_nth_Term( int n) { return 2 * n * n; }
public static void main(String[] args)
{
int N = 6 ;
System.out.println(find_nth_Term(N));
}
}
|
Python
def nthTerm(n):
return 2 * n * n
if __name__ = = "__main__" :
N = 6
print (nthTerm(N))
|
C#
using System;
class GFG {
static int find_nth_Term( int n) { return 2 * n * n; }
public static void Main()
{
int N = 6;
Console.Write(find_nth_Term(N));
}
}
|
Javascript
<script>
function find_nth_Term(n) {
return 2 * n * n;
}
let N = 6;
document.write(find_nth_Term(N) + '<br>' );
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...