0
Can anyone explain me why this code snippet returning 60?
#include <stdio.h> int f(int n, int m){ static int i=10; i*=m+n; if(i>40){ return i; } else{ return f(m+n,m-n); } } int main() { printf("%d",f(2,1)); return 0; }
4 Respuestas
+ 10
f(2,1) //i=10 before this call
= f(3,-1) //i is 30 before this call (10*3)
= 60 //as i becomes 60 in next call f(2,-4), (30*2)
+ 9
f(2,1) //n=2, m=1
= f(1+2,1-2) //n=3, m=-1
+ 1
Gaurav Agrawal ohkay got it thanks
0
Gaurav Agrawal how on second function call f(3,-1) isn't it f(3,1)