#include<stdio.h>
int main()
{
int i,j,a[3][4],max,max_row,max_col;
printf("请输入12个数\n");
for(i=0;i<3;i++)
for(j=0;j<4;j++)
scanf("%d",&a[i][j]);
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];
max_row=i;
max_col=j;
}
}
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
printf("%5d",a[i][j]);
printf("\n");
}
printf("最大的数是 %d,它在第 %d 行 第 %d 列\n",max,max_row+1,max_col+1);
}
Comparing the maximum and minimum will generally set the initial number to the maximum or minimum, and compare them one by one. Build a loop and record the subscript of each number.
The function of this code is to search for known matrix input.