0
[SOLVED] I don't understand why the output is 40320
4 Antworten
+ 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
+ 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.
0
Thanks a lot Mr. Gordon
0
What is the purpose of using these kinds of function?