Hello guys, I still not good at recursion, now I had to do this for homework.

Example: array [1,2,-1,2] , the sequence's average order 1 is 1, order 2 is (1+2)/2=1.5, order 3 is (1+2-1)/3=2/3, order 4 is (1+2-1+2)/4=1

Question: build a function with recursion, the function should be like this **double max_find(int a[], int n, double* avg)**, **a** = array, **n** = array_length, **avg **= I don't know what the hell is that...(the reason why I am asking for solution)

the function returns the max average of the sequence, in the example above it should return 1.5 (cuz it's maximum)

my try was this:

Code:

#include <stdio.h>
double max_find(int a[], int n, double* avg)
{
double we;
if(n < 1)
return a[0];
avg = a[0];
we = (avg + max_find(a+1, n-1, avg))/2;
if(avg > we)
return avg;
else
return we;
}
int main(void)
{
int arr[4] = {1,2,-1,2};
double result;
result = max_find(a, 4, avg);
printf("%lf\n", result);
return 0;
}

__- u can't use loop (for/while)__

- u can't use global variables

- u can't change the values inside the array, even for abit of time

I don't know what I did, cuz of that (double* avg), but any1 help xD

Thank You