配列の最大値を見つけるJavascriptのプログラムがありますが、Cに直接変換したいと思います。以下のJavascriptとCコードを参照してください。
Javascript(動作):
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(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);
}
}
Cコードで何が間違っているのですか?