View Discussion Nội dung chính Improve Article Save Article View Discussion Improve Article Save Article Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720. 1.Recursive approach:python3
Output: Factorial of 5 is 120 Time Complexity: O(n) 2. Iterative approach :Method1: python3
Output: Factorial of 5 is 120 Time Complexity:
O(n) Method2: Python3
Output Factorial of 5 is 120 Time
Complexity: O(n) 3. One line Solution (Using Ternary operator):Python3
Output: Factorial of 5 is 120 Time Complexity: O(n) Please refer complete article on Program for factorial of a number for more details! 4. By using In-built function :In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.factorial() function returns the factorial of desired number. Syntax: math.factorial(x) Parameter: Returns: factorial of desired number. Python3
Output: Factorial of 5 is 120 Method: Using numpy.prodPython3
Output120 Time Complexity: O(n) |