I have a program in Javascript that finds the max value of an array but now I want to translate directly into C. See below of Javascript and C code:
Javascript (works):
var tail = function(arr, pos, max) { //max and pos starts at 0 when called
if (pos === arr.length - 1) {
return arr[pos] > arr[max] ? arr[pos] : arr[max];
}
max = arr[pos] > arr[max] ? pos : max;
return tail(arr, pos += 1, max);
};
C (need to be translated directly from Javascript):
int main(int arr[], int pos, int max) {
if (pos == arr.length - 1) {
return arr[pos] > arr[max] ? arr[pos] : arr[max];
} else {
max = arr[pos] > arr[max] ? pos : max;
return (int arr[], int pos += 1, int max);
}
}
What am I doing wrong in the C code?