Greetings programming community,
How can I get this recursive function that finds the average of an array from any range using specific parameters to work? The parameters are (int a[], int x, int y). The x parameter means begin at and the y means end at.
int k; //no global variables
int average(int A[], int s, int e) {
int x = e+1;
if(s == e) return (k += A[s])/x ;
k += A[s];
average(A, s+1, e);
}
int main() {
int A[5] = {5,7,8,10,2};
cout << average(A,0,4) << endl;
return 0;
}