+ 2
how did came 3 ?
3 odpowiedzi
+ 4
Mouadh Bouziane
You can understand like this also:
5 - fact(4)
= 5 - (4 - fact(3))
= 5 - (4 - (3 - fact(2)))
= 5 - (4 - (3 - (2 - fact(1))))
= 5 - (4 - (3 - (2 - (1 - fact(0)))))
= 5 - (4 - (3 - (2 - (1 - 0))))
= 5 - (4 - (3 - (2 - 1)))
= 5 - (4 - (3 - 1))
= 5 - (4 - 2)
= 5 - 2
= 3
+ 3
fact(5)
5 - fact(4)
4 - fact(3)
3 - fact(2)
2 - fact(1)
1 - fact(0)
fact(0) returns 0
1 - 0 -> returns 1
2 - 1 -> returns 1
3 - 1 -> returns 2
4 - 2 -> returns 2
5 - 2 -> returns 3
So fact(5) = 3
Hope this helps.
+ 2
thanks