Given a number N. The task is to write a program to find the Nth term in the below series:

0, 2, 4, 8, 12, 18…

**Examples:**

Input:3Output:4 For N = 3 Nth term = ( 3 + ( 3 - 1 ) * 3 ) / 2 = 4Input:5Output:12

On observing carefully, the N^{th} term in the above series can be generalized as:

Nth term = ( N + ( N - 1 ) * N ) / 2

Below is the implementation of the above approach:

## C++

`// CPP program to find N-th term of the series: ` `// 0, 2, 4, 8, 12, 18... ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Calculate Nth term of series ` `int` `nthTerm(` `int` `N) ` `{ ` ` ` `return` `(N + N * (N - 1)) / 2; ` `} ` ` ` `// Driver Function ` `int` `main() ` `{ ` ` ` `int` `N = 5; ` ` ` ` ` `cout << nthTerm(N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find N-th term of the series: ` `// 0, 2, 4, 8, 12, 18... ` `import` `java.io.*; ` ` ` `// Main class for main method ` `class` `GFG { ` ` ` `public` `static` `int` `nthTerm(` `int` `N) ` ` ` `{ ` ` ` `// By using above formula ` ` ` `return` `(N + (N - ` `1` `) * N) / ` `2` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `N = ` `5` `; ` `// 5th term is 12 ` ` ` ` ` `System.out.println(nthTerm(N)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 program to find N-th term of the series: ` `# 0, 2, 4, 8, 12, 18. ` ` ` `# Calculate Nth term of series ` `def` `nthTerm(N) : ` ` ` ` ` `return` `(N ` `+` `N ` `*` `(N ` `-` `1` `)) ` `/` `/` `2` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `N ` `=` `5` ` ` ` ` `print` `(nthTerm(N)) ` ` ` `# This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find N-th term of the series: ` `// 0, 2, 4, 8, 12, 18... ` `using` `System; ` `class` `gfg ` `{ ` ` ` `// Calculate Nth term of series ` ` ` `public` `int` `nthTerm(` `int` `N) ` ` ` `{ ` ` ` `int` `n = ((N + N * (N - 1)) / 2); ` ` ` `return` `n; ` ` ` `} ` ` ` ` ` `//Driver program ` ` ` `static` `void` `Main(` `string` `[] args) ` ` ` `{ ` ` ` `gfg p = ` `new` `gfg(); ` ` ` `int` `a = p.nthTerm(5); ` ` ` `Console.WriteLine(a); ` ` ` `Console.Read(); ` ` ` `} ` `} ` `//This code is contributed by SoumikMondal ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find ` `// N-th term of the series: ` `// 0, 2, 4, 8, 12, 18... ` ` ` `// Calculate Nth term of series ` `function` `nthTerm(` `$N` `) ` `{ ` ` ` `return` `(int)((` `$N` `+ ` `$N` `* ` ` ` `(` `$N` `- 1)) / 2); ` `} ` ` ` `// Driver Code ` `$N` `= 5; ` ` ` `echo` `nthTerm(` `$N` `); ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

12

**Time Complexity:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the **Fundamentals of Java and Java Collections Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program to find the Nth term of series -1, 2, 11, 26, 47......
- Program to find Nth term of series 9, 23, 45, 75, 113...
- Find Nth term of series 1, 4, 15, 72, 420...
- Find Nth term of the series 1, 8, 54, 384...
- Find Nth term of the series 4, 2, 2, 3, 6, ...
- Find the Nth term in series 12, 35, 81, 173, 357, ...
- Find Nth term of the series 2, 3, 10, 15, 26....
- Find the Nth term of the series 2, 15, 41, 80, 132...
- Construct an AP series consisting of A and B having minimum possible Nth term
- Find the Nth Pure number
- Program to find the Nth natural number with exactly two bits set
- Find the Nth Hogben Numbers
- Find Nth number in a sequence which is not a multiple of a given number
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Nth Subset of the Sequence consisting of powers of K in increasing order of their Sum
- Print the first N terms of the series 6, 28, 66, 120, 190, 276, ...
- Last digit of sum of numbers in the given range in the Fibonacci series
- Count all possible unique sum of series K, K+1, K+2, K+3, K+4, ..., K+N
- Quick ways to check for Prime and find next Prime in Java
- Find all occurrences of a given word in a matrix

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.