What is output by the following?
===========Code:printf("%d\n", r(5,3)); ... int r (int a, int b) { if (a > b) return a * r(a-1, b); else if (b > 1) return b * r(1, b-1); else return 1; }
The answer is 120, but i don't get it. Obviously the first condition is true, so the C compiler will execute return a * r(a-1, b); which is 5*(4,3). However, im not sure why the compiler is executing 5*4*3*2*1, i thought it would just return5*4*3 and stop. Can someone explain this to be step by step? Thanks.



LinkBack URL
About LinkBacks
? Thanks. 



