#include<iostream>
using namespace std;
int main(){
int i, j, row = 0, colum = 0, max;
int a[3][4] = { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, {454,53,34,56} };
max = a[0][0];
for (i = 0; i <= 2;i++)
for (j = 0; j <= 3; j++)
if (a[i][j] > max)
{
max = a[i][j];
row = i;
colum = j;
}
cout << "max=" << max << " row=" << row << " colum" << colum << endl;
}
#include<iostream>
using namespace std;
int main(){
int max_value(int x, int max);
int i, j, row = 0, colum = 0, max;
int a[3][4] = { { 1, 2, 3, 4 }, { 2, 3, 4, 5 }, {454,53,34,56} };
max = a[0][0];
for (i = 0; i <= 2;i++)
for (j = 0; j <= 3; j++)
{
max = max_value(a[i][j], max);
if (max == a[i][j])
{
row = i;
colum = j;
}
}
cout << "max=" << max << " row=" << row << " colum" << colum << endl;
}
int max_value(int x, int max)
{
if (x > max)
max = x;
return max;
//else return max;
}
max_value()函数不一样,结果一样的。