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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started