+ 5

How make function factorial?

19th Aug 2017, 6:01 PM
vlad.korosko
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))
19th Aug 2017, 6:23 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 5
def factorial(x): d = 1 for x in range(1,x + 1): d = d * x print(d)
22nd Aug 2017, 3:44 PM
vlad.korosko
24th Aug 2017, 9:55 AM
hamletmun
hamletmun - avatar
+ 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++...
20th Aug 2017, 10:54 AM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
17th Nov 2017, 9:27 AM
#RahulVerma
#RahulVerma - avatar