Find which cell holds the biggest number in an array (index from 0); the max itself is then a[index]. Write max_index(a, n) to return that index; if several are tied for biggest, return the first one. 3 9 2 7 returns 1, and 5 1 5 returns 0. The array has at least 1 number.
max_index({3, 9, 2, 7}, 4)→1max_index({5, 1, 5}, 3)→0int max_index(int a[], int n)int max_index(int a[], int n) {
int best = 0;
for (int i = 1; i < n; i++) {
// your code here: if a[i] is bigger than the biggest so far, remember i
}
return best;
}
Run tries the examples. When they look right, Submit.