Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Given already-defined and initialized int variables: 2D array miles, MILES_NU

ID: 3566038 • Letter: 1

Question

1) Given already-defined and initialized int variables: 2D array miles, MILES_NUM_ROWS, MILES_NUM_COLS, i, and j. Write nested loops that assign maxMiles and minMiles with the array's maximum and minimum element values, respectively. Hint: Initialize maxMiles and minMiles realizing that element values could be negative (so don't initialize with value 0).

Below, do not type an entire program. Only type the portion indicated by the above instructions (and if a sample program is shown above, only type the <STUDENT CODE> portion.)

Explanation / Answer

#include<stdio.h>
#define MILES_NUM_ROWS 3
#define MILES_NUM_COLS 4
int main(){
int _2DArray[MILES_NUM_ROWS][MILES_NUM_COLS] = {{12,10,2,5},
{34,98,11,23},
{111,34,1,-1}
};
int maxMiles = _2DArray[0][0];
int minMiles = _2DArray[0][0];
int i = 0,j =0;
for(i = 0; i < MILES_NUM_ROWS; i++){
for(j = 0; j < MILES_NUM_COLS; j++){
if(_2DArray[i][j] > maxMiles){
maxMiles = _2DArray[i][j];
}
if(_2DArray[i][j] < minMiles){
minMiles = _2DArray[i][j];
}
}
}

printf("maxMiles : %d , minMiles : %d",maxMiles,minMiles);
}