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.
how do i set max?????
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
double matrixMax(double M[MAXROWS][MAXCOLS], int numRows, int numCols)
{
for(int r=0; r<numRows; r++)
{
for(int c=0; c < numCols ; c++ )
{
M[MAXROWS][MAXCOLS] = M[numRows][numCols];
}
}
}
In order to find the largest value you have to look at each element and maintain a copy of the largest value that you have found so far. Initialize that copy from the first element.
Write a function called matrixMax that returns the largest element in a matrix of doubles , with numRows and numCols
your function is limited by this double M[MAXROWS][MAXCOLS] Your function can only process arrays of that size, rendering the other parameters meaningless.
You also modify the array, which wasn't the intended operation for the function.
perhaps this is closer to the question..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
double matrixMax(double** matrix, int numRows, int numCols)
{
double max = 0.0;
for(int r=0; r<numRows; r++)
{
for(int c=0; c < numCols ; c++ )
{
if (matrix[numRows][numCols] > max)
{
max = matrix[numRows][numCols];
}
}
}
return max;
}
your function is limited by this double M[MAXROWS][MAXCOLS] Your function can only process arrays of that size, rendering the other parameters meaningless.
That is not entirely true. Yes, the M has a static size that is determined during compilation, but nothing forces it to be filled to the brim. This is legal use: