i am having trouble understanding this example. I cant figure out what actually happens after a certain point.
Here is the code, the result is supposed to be 4.
Recursion is the process of repeating itself several times until the condition is true.
Here the function recursion returns the value 3 if i>1 is false and if true it calls recursively.
As i=9, first time it checks 9>1 is true. so, the function returns 9 - recursion(9/2=4) as i is int.
then it calls recursion(4) 4>1 hence, returns 4 - recursion(4/2=2)
again 2>1, returns 2 - recursion(1)
again 1>1 is false, it returns 3 which should substitute in above value i.e., 2-3 = -1.
then 4 - (-1) = 5
9 - 5 = 4.