节 给定程序MODI1.C中,函数 fun 的功能是:从一个3行4列的矩阵中找出最大数及最大数所在位置的下标,函数返回值为最大数,形参 pRow 和 pCol 返回最大数 在位置的下标。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
时间: 2023-05-25 19:02:57 浏览: 187
```c
#include <stdio.h>
int fun(int a[][4], int *pRow, int *pCol);
int main()
{
int x[3][4], i, j, max, row, col;
for(i=0; i<3; i++)
for(j=0; j<4; j++)
scanf("%d", &x[i][j]);
max = fun(x, &row, &col);
printf("max=%d\nrow=%d\ncol=%d\n", max, row, col);
return 0;
}
int fun(int a[][4], int *pRow, int *pCol)
{
int i, j, max, row, col;
row = col = 0; //初始化
max = a[row][col];
for(i=0; i<3; i++)
for(j=0; j<4; j++)
if(a[i][j]>max){
max = a[i][j];
row = i; //更新行
col = j; //更新列
}
*pRow = row; //将最大元素所在的位置下标返回给主调函数
*pCol = col;
return max; //返回最大元素
}
```
阅读全文
相关推荐


















