1(a)- Write a C++ program that finds and displays the maximumvalue in a two - di
ID: 3609418 • Letter: 1
Question
1(a)- Write a C++ program that finds and displays the maximumvalue in a two - dimensional array of integers. the array should bedeclared as a 4- by- 5 array of integers and initialized with thedata 16, 22, 99, 4, 18, -258, 4, 101, 5, 98, 105, 6, 15, 2, 45, 33,88, 72, 16, 3 (b)- Modify the program written in exercise 1 (a) so that italso displays the maximum values's row and column subscriptnumbers. 2- Write a C++ program to select the values in a four by fivearray of positive integers in increasing order and store theselected values in the single- dimensional array named sort. Usethe data statement given in exercise 1 (a) to initialize the twodimensional array. 1(a)- Write a C++ program that finds and displays the maximumvalue in a two - dimensional array of integers. the array should bedeclared as a 4- by- 5 array of integers and initialized with thedata 16, 22, 99, 4, 18, -258, 4, 101, 5, 98, 105, 6, 15, 2, 45, 33,88, 72, 16, 3 (b)- Modify the program written in exercise 1 (a) so that italso displays the maximum values's row and column subscriptnumbers. 2- Write a C++ program to select the values in a four by fivearray of positive integers in increasing order and store theselected values in the single- dimensional array named sort. Usethe data statement given in exercise 1 (a) to initialize the twodimensional array.Explanation / Answer
please rate -thanks#include <iostream.h>
#include <iomanip.h>
using namespace std;
int main()
{int mat[4][5]={16, 22, 99, 4,18,
-258, 4,101,5, 98,
105, 6, 15, 2, 45,
33, 88, 72,16, 3};
int i,j,maxval=-9999999;
cout<<"The Matrix ";
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
{if(mat[i][j]>maxval)
maxval=mat[i][j];
cout<<setw(4)<<mat[i][j]<<" ";
}
cout<<endl;
}
cout<<"The largest value is "<<maxval<<endl;
system("pause");
return 0;
}
part 2
#include <iostream.h>
#include <iomanip.h>
using namespace std;
int main()
{int mat[4][5]={16, 22, 99, 4,18,
-258, 4,101,5, 98,
105, 6, 15, 2, 45,
33, 88, 72,16, 3};
int i,j,maxrow,maxcol,maxval=-9999;
cout<<"The Matrix ";
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
{if(mat[i][j]>maxval)
{maxcol=j;
maxrow=i;
maxval=mat[i][j];
}
cout<<setw(4)<<mat[i][j]<<" ";
}
cout<<endl;
}
cout<<"The largest value is "<<maxval<<" in row"<<maxrow<<" column "<<maxcol<<endl;
system("pause");
return 0;
} part 3 #include<iostream.h>
#include <iomanip.h>
using namespace std;
int main()
{int mat[4][5]={16, 22, 99, 4,18,
-258, 4,101,5, 98,
105, 6, 15, 2, 45,
33, 88, 72,16, 3};
int array[20];
int i,j,k,minrow,mincol,maxval=9999;
cout<<"The Matrix ";
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
cout<<setw(4)<<mat[i][j]<<" ";
cout<<endl;
}
for(k=0;k<=20;k++)
{ maxval=9999;
for(i=0;i<4;i++)
{ for(j=0;j<5;j++)
{if(mat[i][j]<maxval)
{maxval=mat[i][j];
minrow=i;
mincol=j;
}
}
}
array[k]=maxval;
mat[minrow][mincol]=10000;
}
cout<<"Array ";
for(i=0;i<20;i++)
cout<<array[i]<<" ";
cout<<endl;
system("pause");
return 0;
}
part 3 #include<iostream.h>
#include <iomanip.h>
using namespace std;
int main()
{int mat[4][5]={16, 22, 99, 4,18,
-258, 4,101,5, 98,
105, 6, 15, 2, 45,
33, 88, 72,16, 3};
int array[20];
int i,j,k,minrow,mincol,maxval=9999;
cout<<"The Matrix ";
for(i=0;i<4;i++)
{for(j=0;j<5;j++)
cout<<setw(4)<<mat[i][j]<<" ";
cout<<endl;
}
for(k=0;k<=20;k++)
{ maxval=9999;
for(i=0;i<4;i++)
{ for(j=0;j<5;j++)
{if(mat[i][j]<maxval)
{maxval=mat[i][j];
minrow=i;
mincol=j;
}
}
}
array[k]=maxval;
mat[minrow][mincol]=10000;
}
cout<<"Array ";
for(i=0;i<20;i++)
cout<<array[i]<<" ";
cout<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.