finding mean minimum and maximum values

This is a discussion on finding mean minimum and maximum values within the C Programming forums, part of the General Programming Boards category; I am trying to write a function that finds the mean maximum and minimum values for an image yes an ...

finding mean minimum and maximum values

I am trying to write a function that finds the mean maximum and minimum values for an image yes an image, Which is nothing to extraordinarily because it is just a two d matrix of pixel values. So here it was i have so far two for loops that go through the row and column coordinates of the for loop what i am confused on is how to get the mean min and maxium value i know kind of how to do it in words but now so much code

so here are the for loops

for(r=0; r < no_of_rows; r++) {
for(c=0; c < no_of_cols; c++) {

}
}

these will cycle through the row and collum coordinates but how i find the values of the maximum and minim i do not know

I am assuming you have a 2D array named data declared as something like;

Code:

whatever_data_type data[no_of_rows][no_of_cols];

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[0][0].

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.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.