To find the Factorial of positive integer, design an effective algorithm.
In mathematics, factorial of a non-negative integer n is denoted by n!.
As stated in wikipedia, In Indian mathematics, one of the earliest known descriptions of factorials comes from the Anuyogadvāra-sūtra, one of the canonical works of Jain literature, which has been assigned dates varying from 300 BCE to 400 CE. It separates out the sorted and reversed order of a set of items from the other ("mixed") orders, evaluating the number of mixed orders by subtracting two from the usual product formula for the factorial. The product rule for permutations was also described by 6th-century CE Jain monk Jinabhadra. Hindu scholars have been using factorial formulas since at least 1150, when Bhāskara II mentioned factorials in his work Līlāvatī, in connection with a problem of how many ways Vishnu could hold his four characteristic objects (a conch shell, discus, mace, and lotus flower) in his four hands, and a similar problem for a ten-handed god.
A factorial of n items gives you the number of ways you can arrange the given items. For example: If there are two coins - you can arrange them in two different ways - like wise if you have 3 coins - there are 6 ways you can arrange them.
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = int(input("Enter a number: "))
result = factorial(num)
print("The factorial of", num, "is", result)
The Factorial of the number is
__________.
Let us consider, there are three distinct objects are we are asked to arrange them in a number of ways..... to see those arrangements.
There will be 6 methods to arrange them in the required order. Thus the factorial of 3 means, there are 6 methods to arrange 3 distinct objects. Hence, n! means there are this much ways to arrange n distinct objects.
Hence we can find the factorial of a number by repeated multiplication.