Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

3. Identify challenges to good listening and their remedies

Answered: 1 week ago

Question

4. Identify ethical factors in the listening process

Answered: 1 week ago