Find nth term of 0, 9, 24, 45, . . . .
Last Updated :
01 Feb, 2022
Given a natural number N, the task is to find the Nth term of the series
0, 9, 24, 45, . . . .till N terms
Examples:
Input: N = 4
Output: 45
Input: N = 6
Output: 105
Approach:
From the given series, find the formula for Nth term-
1st term = 3 * 1 * 1 – 3 = 0
2nd term = 3 * 2 * 2 – 3 = 9
3rd term = 3 * 3 * 3 – 3 = 24
4th term = 3 * 4 * 4 – 3 = 45
.
.
Nth term = 3 * N * N – 3
The Nth term of the given series can be generalized as-
TN = 3 * N * N – 3
Illustration:
Input: N = 6
Output: 105
Explanation:
TN = 3 * N * N – 3
= 3 * 6 * 6 – 3
= 108 – 3
= 105
Below is the implementation of the above approach-
C++
#include <iostream>
using namespace std;
int nth_Term( int n)
{
return 3 * n * n - 3;
}
int main()
{
int N = 6;
cout << nth_Term(N) <<
endl;
return 0;
}
|
Java
import java.util.*;
public class GFG
{
static int nth_Term( int n)
{
return 3 * n * n - 3 ;
}
public static void main(String args[])
{
int N = 6 ;
System.out.println(nth_Term(N));
}
}
|
Python3
def nth_Term(n):
return 3 * n * n - 3 ;
N = 6 ;
print (nth_Term(N))
|
C#
using System;
class GFG
{
static int nth_Term( int n)
{
return 3 * n * n - 3;
}
public static void Main()
{
int N = 6;
Console.WriteLine(nth_Term(N));
}
}
|
Javascript
<script>
function nth_Term(n) {
return 3 * n * n - 3;
}
let N = 6;
document.write(nth_Term(N) + '<br>' )
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...