hi! i want to splt the array into sections of 2 values, recursively. the objective its to do the average.
i have this input and output, that its correct:
> media_recursiva a 1 a 2 a 4 a 5 a 2 a 3 a 5 a 6
1.000
1.500
3.000
3.500
("a 1" means add the value 1)
but mine its wrong, it gives to me this:
1.000
1.000
2.500
3.000
Code:
float media(int arr[], int count)
{
while(count != 0){
if(count==1)
return arr[0];
else if(count ==2){
return ((arr[0] + arr[1])/2);
}
else{
int *fHalf = arr;//first half of array
int *sHalf = arr + (count/2);//second half
return (media(fHalf, (count/2)) + media(sHalf, (count/2)))/2;
}
}
}
thanks