有一个3X4的矩阵,要求编程程序求出其中值的最大的那个元素的值,以及其所在的行号和列号

#include <stdio.h>
int main() {

    int arr[3][4] = {
        {1,2,3,4},
        {9,8,7,6},
        {-10,10,-5,2}
    };

    int i,j,row=0,colum=0,max;
    max = arr[0][0];

    for(i=0;i<=2;i++){
        for(j=0;j<=3;j++){
            if(arr[i][j]>max){
                max = arr[i][j];
                row = i;
                colum = j;
            };
        };
    };

    printf("max=%d\nrow=%d\ncolum=%d\n",max,row,colum);

    return 0;
}
结果:
max=10
row=2
colum=1

Process returned 0 (0x0)   execution time : 0.019 s
Press any key to continue.
posted @ 2024-11-08 22:43  昵-称  阅读(137)  评论(0)    收藏  举报