maximum, minimum and average of a matrix?

std::vector<std::vector<unsigned long> > matrix(15); // 15 rows
typedef std::vector<std::vector<unsigned long> >::iterator it_type;

it_type row = matrix.begin();

for (int w=0;w<10;w++)
{
//some lines of code
unsigned long num = x.to_ulong();
cout <<"Decimal form is: " << num<< end;
// if we've hit 15 items in the current row (i.e. 15 columns), then shift to the next row
if (row->size() == 15)
++row;

// add this to the next column in the current row
row->push_back(num);
}
// resize the last row
row->resize(15); // this will ensure that there are 15 columns in the last row


for(size_t i=0; i < matrix.size(); ++i)
{
for(size_t j=0; j < matrix[i].size(); ++j)
cout << matrix[i][j] << " ";
cout << endl;
}

Now I want to find maximum, minimum and average of this matrix. What shall I do?
here's a hint..

int max = matrix [0][0];
1
2
3
4
5
6
7
for (i=0; i<m; i++) {
for (j=0; j<0; j++)

if (matrix[i][j]>max)
max = matrix [i][j];
}
cout<<"The max value of the marix is: "<<max;

Last edited on
main problem is,
1
2
for (i=0; i<m; i ++) {
for (j=0; j<0; j++0)


how to select value for m, and j=o;j<0? we need to find value for j as well. how should i do that?
Topic archived. No new replies allowed.