What value would the following function return for the input $x=95$?
Function fun (x:integer):integer;
If x > 100 then fun = x – 10
Else fun = fun(fun (x+11))
Hint: Keep track of the stack and you'll reach fun(fun(111))
And fun(111) returns 101.
Substitute this, and we get fun(101). Now, IF will be true, not ELSE (up to this point, each time ELSE was true => recursive call. But now ELSE isn't true anymore)
Which makes fun(101) set the value as 91.
There are no more recursive calls, the execution halts here. 91 is the correct answer.
= f(f(106) = f(96)
= f(f(107) = f(97)
= f(f(108) = f(108)
= f(f(109) = f(109)
= f(f(110) = f(100)
= f(f(111) = f(101) = 91
fun = x – 10
how can u say that this is calling fun(x-10).........is it pascal syntax?