+ 5
How make function factorial?
5 Answers
+ 7
# Iteratively:
def IterativeFactorial(x):
if x==0 or x==1:
return 1
fact = 1
for i in range(2, x+1):
fact *= i
return fact
# Recursively:
def RecursiveFactorial(x):
if x==0 or x==1:
return 1
return x * RecursiveFactorial(x-1)
# test, should print out 6! ==> 720
print(IterativeFactorial(6))
print(RecursiveFactorial(6))
+ 5
def factorial(x):
d = 1
for x in range(1,x + 1):
d = d * x
print(d)
+ 2
Factorial: Multiply n * n-1 * n-2 ... 2 (ex. 5*4*3*2)
https://code.sololearn.com/cRR0883g759i/?ref=app
https://code.sololearn.com/ciZe5KbLj3hT/?ref=app
+ 1
This code has a Factorial Function...
https://code.sololearn.com/c0BVJZcyO3cY/?ref=app
But that's Java, and you can turn it into C++...