0

[SOLVED] I don't understand why the output is 40320

https://code.sololearn.com/WqhdZt3MFKV4

2nd Mar 2020, 12:44 AM
JS LOVER
JS LOVER - avatar
4 odpowiedzi
+ 7
factorial(8) => 8 == 0 false, goes to else block => factorial(8-1)*8 where factorial(7) = factorial(6)*7 ... until factorial(0) returns 1 so factorial(8) = 1*1*2*3...*7*8
2nd Mar 2020, 1:05 AM
Gordon
Gordon - avatar
+ 1
You are welcome. This is called recursion. You need a ending condition to escape from infinite loop. Try coding a Fibonacci with recursion as exercise.
2nd Mar 2020, 8:46 AM
Gordon
Gordon - avatar
0
Thanks a lot Mr. Gordon
2nd Mar 2020, 7:30 AM
JS LOVER
JS LOVER - avatar
0
What is the purpose of using these kinds of function?
3rd Mar 2020, 7:21 AM
JS LOVER
JS LOVER - avatar