+ 1
I don't really get how the output of this code is 9
https://code.sololearn.com/cMpTas3Q0SMj/?ref=app https://code.sololearn.com/cMpTas3Q0SMj/?ref=app
2 Answers
+ 5
It recursively transforms the multiplication into a series of additions. The first call to multi is with 5,5, which gets transformed into multi(4,5)+5, which is transformed into multi(3,5)+5+5, etc. In the end we have multi(0, 5)+5+5+5+5+5. Multi(0,5) returns 0 because of the if statement and then all the 5s are added together. So it's a way to transform multiplication into additions.
+ 1
Thanks guys for the detailed and we'll explained explanations