Question: 1. (40 pts) Consider the following function. Complete the function so it sets the maximum value in the array in the variable pointed to by
1. (40 pts) Consider the following function. Complete the function so it sets the maximum value in the array in the variable pointed to by max and returns a pointer to the minimum value in the array:
int * findMinAndMax(int a[ ], int length, int * max) {
int maxValue = a[0], minValue = a[0];
int maxIdx = 0, minIdx = 0;
for (int idx =1; idx < length; idx++) {
if (a[idx] > maxValue) {
maxValue = a[idx];
maxIdx = idx;
}
if (a[idx] < minValue) {
minValue = a[idx];
minIdx = idx;
}
}
}
2. (60 pts) Consider the above function. Declare an integer array called myArray of length 5. Initialize myArray to 4, 1, -5, 3, 5, in sequence. Declare two pointers ptrMin and ptrMax, both pointing to integer. Call the above function so that the min index is at pointer ptrMin and the max pointer is at ptrMax.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
