Related Articles

# Program to find Nth term of series 1, 3, 12, 60, 360…

• Difficulty Level : Medium
• Last Updated : 25 Feb, 2021

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

`1, 3, 12, 60, 360…`

Examples:

Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the  Demo Class for First Step to Coding Coursespecifically designed for students of class 8 to 12.

The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.

```Input: 2
Output: 3

Input: 4
Output: 60```

Approach: The idea is to first find the factorial of the number (N+1), that is (N+1)!
Now, the N-th term in the above series will be:

`N-th term = (N+1)!/2`

Below is the implementation of the above approach:

## C++

 `// CPP program to find N-th term of the series:``// 1, 3, 12, 60, 360…` `#include ``using` `namespace` `std;` `// Function to find factorial of N``int` `factorial(``int` `N)``{``    ``int` `fact = 1;` `    ``for` `(``int` `i = 1; i <= N; i++)``        ``fact = fact * i;` `    ``// return factorial of N+1``    ``return` `fact;``}` `// calculate Nth term of series``int` `nthTerm(``int` `N)``{``    ``return` `(factorial(N + 1) / 2);``}` `// Driver Function``int` `main()``{` `    ``// Taking n as 6``    ``int` `N = 6;` `    ``// Printing the nth term``    ``cout << nthTerm(N);` `    ``return` `0;``}`

## Java

 `// Java program to find N-th``// term of the series:``// 1, 3, 12, 60, 360` `import` `java.util.*;``import` `java.lang.*;``import` `java.io.*;` `class` `GFG {` `    ``// Function to find factorial of N``    ``static` `int` `factorial(``int` `N)``    ``{``        ``int` `fact = ``1``;` `        ``for` `(``int` `i = ``1``; i <= N; i++)``            ``fact = fact * i;` `        ``// return factorial of N``        ``return` `fact;``    ``}` `    ``// calculate Nth term of series``    ``static` `int` `nthTerm(``int` `N)``    ``{``        ``return` `(factorial(N + ``1``) / ``2``);``    ``}` `    ``// Driver Code``    ``public` `static` `void` `main(String args[])``    ``{` `        ``// Taking  n as 6``        ``int` `N = ``6``;` `        ``// Printing the nth term``        ``System.out.println(nthTerm(N));``    ``}``}`

## Python3

 `# Python 3 program to find``# N-th term of the series:``# 1, 3, 12, 60, 360…` `# Function for finding``# factorial of N``def` `factorial(N) :``    ``fact ``=` `1``    ``for` `i ``in` `range``(``1``, N ``+` `1``) :``        ``fact ``=` `fact ``*` `i` `    ``# return factorial of N``    ``return` `fact` `# Function for calculating``# Nth term of series``def` `nthTerm(N) :` `    ``# return nth term``    ``return` `(factorial(N ``+` `1``) ``/``/` `2``)` `# Driver code``if` `__name__ ``=``=` `"__main__"` `:``    ` `    ``N ``=` `6` `    ``# Function Calling``    ``print``(nthTerm(N))`

## C#

 `// C# program to find N-th``// term of the series:``// 1, 3, 12, 60, 360``using` `System;` `class` `GFG``{``    ` `// Function to find factorial of N``static` `int` `factorial(``int` `N)``{``    ``int` `fact = 1;` `    ``for` `(``int` `i = 1; i <= N; i++)``        ``fact = fact * i;` `    ``// return factorial of N``    ``return` `fact;``}` `// calculate Nth term of series``static` `int` `nthTerm(``int` `N)``{``    ``return` `(factorial(N + 1) / 2);``}` `// Driver Code``static` `void` `Main()``{``    ``int` `N = 6 ;``    ` `    ``// Printing the nth term``    ``Console.WriteLine(nthTerm(N));``}``}` `// This code is contributed``// by ANKITRAI1`

## PHP

 ``

## Javascript

 ``
Output:
`2520`

My Personal Notes arrow_drop_up