#include<stdio.h>
int main()
{
int i,j,row,colum;
int a[3][4] = { {1,2,3,4},{9,8,7,6},{-10,10,-5,2} };
int 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;
}
}
}
printf("%d\n%d\n%d\n", max,row,colum);
return 0;
}
1上面是打擂台法
2运用多维数组参与函数
#include <stdio.h>
int max(int x[][4]);
int main() {
int a[][4] = { {1,3,5,7},{2,4,6,8},{15,17,34,12} };
printf("%d", max(a));
return 0;
}
int max(int x[][4]) {
int i, j;
int max1= x[0][0];
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
if (x[i][j] >= max1) {
max1 = x[i][j];
}
}
}
return max1;
}