【描述】
有一个3*4的矩阵,要求编程序求出其中值最大的那个元素的值,以及其所在的行号和列号。
【输出结果】
max=10 row=2 colum=1
【C语言】
#include<stdio.h>
int main() {
int i, j;
int max, row, colum;
int a[3][4] = { { 1, 2, 3, 4 }, { 9, 8, 7, 6 }, { -10, 10, -5, 2 } };
max = a[0][0];
for (i = 0; i < 3; i++)
for (j = 0; j < 4; j++)
if (max < a[i][j]) {
max = a[i][j];
row = i;
colum = j;
}
printf("max=%d row=%d colum=%d\n", max, row, colum);
return 0;
}