I am assuming you have a 2D array named data declared as something like;
and populated with a set of values before your loop.
Before the loop, declare variables named maximum and minimum, and set both of them to data.
In the body of the loop, compare data[r][c] with minimum and maximum. It is a nobrainer that, if data[r][c] is less than minimum, the value of minimum needs to be updated and that if data[r][c] is greater than maximum, the value of maximum needs to be updated.
This approach works regardless of the actual data type (whatever_data_type can be int, float, double, .....) as long as it is possible to compare values.