Re: recursive function average(int n)?



so the answer is actually (helped by my wife):
if n = 1
return 1
else
return 1+(n-1)*avarage(n-1)/n

5
1 + 4*aveg(4)/5 = 1 + 4*2.5/5 = 3


4
1 + 3*aveg(3)/4 = 1 + 3*2/4 = 2.5


3
1 + 2*aveg(2)/3 = 1 + 2*1.5/3 = 2

2
1 + 1*aveg(1)/2 = 1 + 1/2

aveg(1)
1

.