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

Write a C++ program that finds and displays the maximum value in a two-dimension

ID: 3850042 • Letter: W

Question

Write a C++ program that finds and displays the maximum value in a two-dimensional array of integers. The array should be declared as a 4-by-5 array of integers and initialized with the data 16, 22, 99, 4, 18, -258, 4, 101, 5, 98, 105, 6, 15, 2, 45, 33, 88, 72, 16, and 3. MODIFY THE PROGRAM SO THAT IT ALSO DISPLAYS THE MAXIMUM VALUE'S ROW AND COLUMN SUBSCRIPT NUMBERS!! THE ARRAY SHOULD BE INITIALIZED USING THE NUMBERS IN THE PROBLEM. DISPLAY BOTH THE MAXIMUM NUMBER AND THE ROW AND COLUMN INDEX OF IT'S LOCATION!!

** Here is the textbook solution for this problem. The only thing that I see that they left out was the last part of the problem that I have restated in bold, where you are supposed to show NOT JUST the first row's maximum value, BUT THE MAXIMUM NUMBER, AND ALSO THE ROW AND COLUMN INDEX OF IT'S LOCATION!! :

10 #include Kiostream> using namespace std; 11 12 13 int main 14 int i, j, max; 15 16 E int arry[4][5] 16, 22, 99, 4, 18, -258, 4, 101, 5, 98, 105, 6, 15, 2, 17 45 33, 88, 72, 16, 3 arry[0] [e]; 18 maX 19 20 for (i ez i K 4; ++i) 21 22 max 0; for (j 0; j k 5; ++j) 23 24 if (arry [i][j] max) 25 26 max arry[i][jl; 27 28 30 31 cout "The Maximum Value Of This Row Is KK max endl endl 32 33 system ("pause"); 34 35 36 return 0 37

Explanation / Answer

Program:

#include<iostream>

using namespace std;

int main()
{
    int max,i,j;
    int row,column;
    int a[4][5]={16,22,99,4,18,-258,4,101,5,98,105,6,15,2,45,33,88,72,16,3};
   max=a[0][0];


    for(i=0;i<4;++i){
  
        for(j=0;j<5;++j)
        {
            if(a[i][j]>max)
                max=a[i][j];
                row=i;
                column=j;
        }}
cout<<" Largest number: "<<max<<" at row "<< row <<" at column "<<column;
  
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote