-->
当前位置:首页 > 题库 > 正文内容

程序填空题:查找二维数组中的最大值及其行列下标

Luz3年前 (2022-03-03)题库1180
本题目查找二维数组中的最大值及其行列下标
c++
输入:
3 5 -1 4
7 -32 0 9
-102 45 78 4
输出:
max=78 maxr=2 maxc=2

#include <stdio.h>
#define ROW 20
#define COL 15
int FindMaxbyRow(int (*p)[COL],int row,int col,int *maxRow,int *maxCcol);
int main(void)
{
int a[ROW][COL];
int max,maxr,maxc;
int i,j;
for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
scanf("%d",&a[i][j]);
}

printf("max=%d maxr=%d maxc=%d\n",max,maxr,maxc);
return 0;
}
int FindMaxbyRow(int (*p)[COL],int row,int col,int *maxRow,int *maxCcol)
{
int i,j;
int max;

*maxRow=0;
*maxCcol=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if()
{

*maxRow=i;
*maxCcol=j;
}
}
}

}






答案:
第1空:max=FindMaxbyRow(a,ROW,COL,&maxr,&maxc);

第2空:max=p[0][0];

第3空:p[i][j]>max

第4空:max=p[i][j];

第5空: return max;

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。