0
The out of this code is 337 but why?
function mlt(a, b) { if(!(a&&b)){ return 0; } else if(b==1){ return a; } else { return (a + mlt(a, b-1)); } } document.write(mlt(3, 11)); document.write(mlt(7, 1));
2 Answers
+ 3
Romjan Ali
else part will be execute till b = 1
so 3 + 3 + 3 + 3.....till 11 times so total = 3 * 11 = 33
Now for mlt(7, 1) will be only once because b = 1 so mlt function will return 7
So 337
- 1
You forgot to put newline between two print statements, so two results 33 & 7 are printed on the same line (337)
Last 3 lines should be
document.write(mlt(3,11));
document.write("\n");
document.write(mlt(7,1));