+ 2

Factorial

https://code.sololearn.com/cqMK0HnC1FgF/?ref=app I coded a function that calls itself; Basically it gets the factorial of any number, but when the number is bigger than 100 it gets returned as if it’s factorial is equal to 0. However this only happens when you define the function as an integer. Why does it happen?

6th Sep 2019, 5:11 PM
Drodrigues
2 ответов
+ 6
If I understand what you're saying, you can't input a decimal number (2.4, 3.1, etc.) because the condition to end the recursive function requires that the value eventually equals 1 by subtracting 1 to it repeatedly. Because you cannot subtract decimal numbers by 1 to reach 1, it will never actually exit the loop and therefore create an infinite loop
6th Sep 2019, 5:38 PM
Faisal
Faisal - avatar
+ 4
Using your program I got 200! = 7.88658e+374 so it seems to work for integers larger than 100. Also tested and works for 1500!
6th Sep 2019, 11:33 PM
Sonic
Sonic - avatar