Consider the following function:
public int mystery(int n, int a , int d) {
if(n == 1)
return a;
else
return d + mystery(n - 1, a, d);
}
What value is returned by the
call mystery(n,a,d)?
(Either write a number, or write "infinite recursion".)
ANS
If you trace this function, you should find that d is added to it self n-1 times. Then in the nth time (the base case), a is added to the sum.