1. ## C program help

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)

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

2. This site has a homework policy, here. It amounts to "do your own homework".

Finding code that someone else has written, and begging in a forum for an explanation of how it works in case your teacher asks for an explanation, does not qualify as doing your own homework.

Not that it really matters in this case. That code is not valid C, so will not even compile, let alone produce the results required of your homework.

3. Originally Posted by grumpy
This site has a homework policy, here. It amounts to "do your own homework".

Finding code that someone else has written, and begging in a forum for an explanation of how it works in case your teacher asks for an explanation, does not qualify as doing your own homework.

Not that it really matters in this case. That code is not valid C, so will not even compile, let alone produce the results required of your homework.
very well,
1st I didn't know that policy, so now I know.
2nd I didn't take that code from anyone I coded it.
3rd that's god to know it's an error code (won't compile)
4th I just asked for help, in my homework question, no big deal tho.

4. My guess of the main function.
Note: The use of literal "4" in the code is NOT correct thing to do.

I did the smallest code change that looked correct; I have NOT compiled the code.

Tim S.

Code:
```int main(void)
{
int arr[4] = {1,2,-1,2};
double result;
double avg = arr[0];

result = max_find(a, 4, &avg);
printf("%lf\n", result);

return 0;
}```

5. Thanks for the help mate, what I found hard was only that ((double* avg)) thing, I was like "what the heck should I do with it" Lol

6. Originally Posted by ConanCoder
very well,
1st I didn't know that policy, so now I know.
2nd I didn't take that code from anyone I coded it.
3rd that's god to know it's an error code (won't compile)
4th I just asked for help, in my homework question, no big deal tho.