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

Write a function called matrixMax that returns the largest element in a matrix o

ID: 3544997 • Letter: W

Question

Write a function called matrixMax that returns the largest element  in a matrix of doubles , with numRows and numCols. A function definition skeleton is provided. Note that the problem does not call for you to output  to the console, so do not output . Also, it does not call for you to input from the console, so do not input.


double matrixMax(double M[MAXROWS][MAXCOLS], int numRows, int numCols)

{



}




In the previous problem you wrote a matrixMax function that returns the maximum element  in a matrix of doubles . Now imagine you are writing part of the main program , and your goal is to call this function... In particular, assume  a matrix named  data has been declared  for you in main(), and that it is already  filled with values . Assume  the matrix has N rows and N columns, where N has already  been declared  for you. Write a *CODE FRAGMENT* to call matrixMax to return the maximum element  in data, and then output  this value  to the console.


Instructor's notes: NOTE: you are writing a code frament to call the function and output the value that is returned; do not write a complete program.  And you do not need to define the function, assume it is there and just call it. You should probably review the previous problem to see how the function was defined so that you pass the correct parameters --- pass the array, the number of rows, and the number of columns.

Explanation / Answer

double matrixMax(double M[MAXROWS][MAXCOLS], int numRows, int numCols)

{

double max;

//set index 0 0 to max first

max = M[0][0];

for(int i = 0; i < numRows; i++){

for(int j = 0; j < numCols; j++){

if( M[i][j] > max){

max = M[i][j];

}

}

}

return max;

}


Code Fragment:


cout << "Maximum element if the matrix is : " << matrixMax(data, n, n) << endl;

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