Question
a. Write a function named findmax() that finds and displays the maximum values in a two dimensional array of integers. The array should be declared
a. Write a function named findmax() that finds and displays the maximum values in a two dimensional array of integers. The array should be declared as a 10 row by 20 column array of integers in main() and populated with random numbers between 0 and 100.
b. Modify the function written above so that it also displays the row and column numbers of the element with the maximum value.
I have this so far, and but it's only finding the MAX of the last column/row.... and I need to display the row/column where this MAX value resides/stays/lives....:
#include
int main() { srand(time(NULL));
const int row = 10; int array[row][20];
for (int k = 0; k < row; k++) { for (int i = 0; i < 20; i++) { array[k][k] = rand() % (100 + 1); cout << array[k][k] << " "; } cout << endl; } int max1 = findmax(array); cout << "The maximum value is " << max1 << endl;
system("pause"); return 0; }
int findmax(int array[][20]) { int i, j; int max = array[0][0];
for (i = 1; i < 10; i++) for (j = 1; j < 20; j++) if (array[i][j] > max) { max = array[i][j]; } return max; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started