#include <stdio.h>
#define N 10
int find_largest(int *, int );
int main(void) {
int a[] = {1,2,23,4,5,2,14,6,8,10};
printf("%d\n", find_largest (a, N));
}
int find_largest(int *a, int n) {
int i, max;
max = a[0];
for (i = 1; i < n; i++)
if (a[i] > max)
max = a[i];
return max;
}
How can I edit the function call so that the program prints the maximum number of the second half of the array, so among these elements: {2, 14, 6, 8, 10}?
As I said, I should edit only this line:
printf("%d\n", find_largest (a, N));
Thank you 🙂
You can change that line as:
The
(N+1)/2can handle the exception whenNis an odd number.