- 论坛徽章:
- 145
|
回复 3# yzxarlen
you have to know the recursion
f(n) = f(n-1) * n
f(1) = 1
1. f(5)
you can't get the result for f(5)
call f(4) * 5
2. f(4)
you can't get the result for f(4)
call f(3) * 4
...
3. f(3)
you can't get the result for f(3)
call f(2) * 3
...
4. f(2)
you can't get the result for f(2)
call f(1) * 2
5. f(1)
Now, you can get the result 1 for f(1)
use global r variable return the value 1
6. f(2) get result 2 by f(1) * 2
7. f(3) get result 6 by f(2) * 3
8. f(4) get result 24 by f(3) * 4
8. f(5) get result 120 by f(4) * 5
|
|