Find Nth term of the series 1, 1, 2, 6, 24…
Given a number N. The task is to write a program to find the Nth term in the below series:
1, 1, 2, 6, 24…
Examples:
Input: 3
Output: 2
For N = 3
Nth term = (N-1)!
= 2
Input: 5
Output: 24
Nth term of the series is given by below formula:
Nth term = ( N-1)!
Below is the required implementation:
C++
// CPP program to find N-th term of the series: // 1, 1, 2, 6, 24... #include <iostream> using namespace std; // calculate Nth term of series int nthTerm(int N) { if (N <= 1) return 1; int i, fact = 1; for (i = 1; i < N; i++) fact = fact * i; return fact; } // Driver Function int main() { int N = 3; cout << nthTerm(N); return 0; } |
chevron_right
filter_none
Java
// Java program to find the Nth term import java.io.*; // calculate Nth term of this series // 1, 1, 2, 6, 24... class Nth { public int nthTerm(int N) { // By using above formula if (N <= 1) return 1; int i, fact = 1; for (i = 1; i < N; i++) fact = fact * i; return fact; } } // Main class for main method class GFG { public static void main(String[] args) { int N = 3; // create object of Class Nth Nth a = new Nth(); // call and print Nth term System.out.println(a.nthTerm(N)); } } |
chevron_right
filter_none
Python 3
# Python 3 program to find # N-th term of the series: # 1, 1, 2, 6, 24... # Function to calculate # Nth term of series def nthTerm(n) : if n <= 1 : return 1 fact = 1 for i in range(1, N) : fact = fact * i return fact # Driver code if __name__ == "__main__" : N = 3 # function calling print(nthTerm(N)) # This code is contributed # by ANKITRAI1 |
chevron_right
filter_none
C#
// C# program to find the // Nth term of the series // 1, 1, 2, 6, 24... using System; // calculate Nth term class GFG { public int nthTerm(int N) { // By using above formula if (N <= 1) return 1; int i, fact = 1; for (i = 1; i < N; i++) fact = fact * i; return fact; } // Driver Code public static void Main() { int N = 3; // create object of Class GFG GFG a = new GFG(); // call and print Nth term Console.Write(a.nthTerm(N)); } } // This code is contributed // by ChitraNayal |
chevron_right
filter_none
PHP
<?php // PHP program to find N-th // term of the series: // 1, 1, 2, 6, 24... // calculate Nth term of series function nthTerm($N) { if ($N <= 1) return 1; $fact = 1; for ($i = 1; $i < $N; $i++) $fact = $fact * $i; return $fact; } // Driver Code $N = 3; echo nthTerm($N); // This code is contributed // by ChitraNayal ?> |
chevron_right
filter_none
Output:
2
Recommended Posts:
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series 0, 6, 0, 12, 0, 90...
- Find Nth term of the series 1, 8, 54, 384...
- Find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ...
- Find n-th term of series 3, 9, 21, 41, 71...
- Find the nth term of the series 0, 8, 64, 216, 512, . . .
- Find Nth term of the series 5, 13, 25, 41, 61...
- Find Nth term of the series 3, 14, 39, 84...
- Find the nth term of the given series
- Find n-th term of series 2, 10, 30, 68, 130 ...
- Find the Nth term of the series 14, 28, 20, 40,.....
- Find n-th term in the series 9, 33, 73,129 ...
- Find sum of Series with n-th term as n^2 - (n-1)^2
- Find n-th term in the series 7, 15, 32, ...
- Find Nth term of the series 1, 6, 18, 40, 75, ....
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.



