Question

In: Computer Science

Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and...

Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program:

Min miles: -10
Max miles: 40

#include <iostream>
using namespace std;

int main() {
const int NUM_ROWS = 2;
const int NUM_COLS = 2;
int milesTracker[NUM_ROWS][NUM_COLS];
int i;
int j;
int maxMiles = -99; // Assign with first element in milesTracker before loop
int minMiles = -99; // Assign with first element in milesTracker before loop
int value;

for (i = 0; i < NUM_ROWS; i++){
for (j = 0; j < NUM_COLS; j++){
cin >> value;
milesTracker[i][j] = value;
}
}

/* Your solution goes here */

cout << "Min miles: " << minMiles << endl;
cout << "Max miles: " << maxMiles << endl;

return 0;
}

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main() {
    const int NUM_ROWS = 2;
    const int NUM_COLS = 2;
    int milesTracker[NUM_ROWS][NUM_COLS];
    int i;
    int j;
    int maxMiles = -99;
    int minMiles = -99;

    int value;
    for (i = 0; i < NUM_ROWS; i++) {
        for (j = 0; j < NUM_COLS; j++) {
            cin >> value;
            milesTracker[i][j] = value;
        }
    }

    minMiles = milesTracker[0][0];
    maxMiles = milesTracker[0][0];
    for (i = 0; i < NUM_ROWS; ++i) {
        for (j = 0; j < NUM_COLS; ++j) {
            if (milesTracker[i][j] > maxMiles)
                maxMiles = milesTracker[i][j];
            if (milesTracker[i][j] < minMiles)
                minMiles = milesTracker[i][j];
        }
    }

    cout << "Min miles: " << minMiles << endl;
    cout << "Max miles: " << maxMiles << endl;
    return 0;
}

Related Solutions

(in java) Find the maximum value and minimum value in milesTracker. Assign the maximum value to...
(in java) Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 given code below (please bold the solution, thank you!) import java.util.Scanner; public class ArraysKeyValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_ROWS = 2; final int NUM_COLS = 2; int [][] milesTracker = new int[NUM_ROWS][NUM_COLS]; int...
Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and...
Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 import java.util.Scanner; public class ArraysKeyValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_ROWS = 2; final int NUM_COLS = 2; int [][] milesTracker = new int[NUM_ROWS][NUM_COLS]; int i; int j; int maxMiles; // Assign with first element in...
Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and...
Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 Java Code: Remember we can only add to the code. We cant change whats already given. Thank you. import java.util.Scanner; public class ArraysKeyValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_ROWS = 2; final int NUM_COLS = 2;...
Find the relative maximum and minimum value if the following one variable function (If there is...
Find the relative maximum and minimum value if the following one variable function (If there is any): a) y = x^2 + 2x + 1 b) y = 6x^2 - 12x c) y = x^2 + 2x + 1 d) y = x^4
Find the absolute maximum value and absolute minimum value, if any, of the function g(x) =...
Find the absolute maximum value and absolute minimum value, if any, of the function g(x) = x √(4 − x2) on the interval [−2, 2].
1. Find the absolute minimum and maximum value of f(x) = x4 − 18x 2 +...
1. Find the absolute minimum and maximum value of f(x) = x4 − 18x 2 + 7 (in coordinate form) on [-1,4] 2. If f(x) = x3 − 6x 2 − 15x + 3 discuss whether there are any absolute minima or maxima on the interval (2,∞) show work please
Find the intervals of increase and decrease, find the local maximum and minimum values, find the...
Find the intervals of increase and decrease, find the local maximum and minimum values, find the intervals of concave up and concave down, find the inflection points and sketch the graph f(deta) = 2cos(deta)+cos^2(deta), 0<=deta<=2pi
This extreme value problem has a solution with both a maximum value and a minimum value....
This extreme value problem has a solution with both a maximum value and a minimum value. Use Lagrange multipliers to find the extreme values of the function subject to the given constraint. f(x, y) = x2 − y2;    x2 + y2 = 16
Find the absolute maximum and absolute minimum values of the function, if they exist, on the...
Find the absolute maximum and absolute minimum values of the function, if they exist, on the indicated interval. 6) f(x) = x 4 - 32x 2 + 2; [-5, 5]
find the absolute minimum and absolutely maximum value of function f(x,y)= e^xy subject to the constraint...
find the absolute minimum and absolutely maximum value of function f(x,y)= e^xy subject to the constraint x^2+y^2= 18
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT