f
below:
int f(int a, int b) { int ans; if (a > b) ans = 0; else ans = a + f(a+1, b); return ans; }
f(4,6)
. Show the parameters and return
values at each step.
f(a,b)
return? That is,
what task does f
perform?
target
in array a
, or -1
if target
does not appear in a
.
int find(int[] a, int target, int index) { int loc; if (a[index] == target) loc = index; else loc = find(a, target, index+1); return loc; }
1 + 5 + 9 + ... + 4i-3 = n(2n-1)