程序填空题:查找二维数组中的最大值及其行列下标
本题查找二维数组中的最大值及其行列下标
c++
输入:
3 5 -1 4
7 -32 0 9
-102 45 78 4
输出:
max=78 maxr=2 maxc=2
#include <stdio.h>
#define ROW 3
#define COL 4
int FindMaxbyCol(int *q,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 FindMaxbyCol(int *q,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=FindMaxbyCol(a[0],ROW,COL,&maxr,&maxc);
第2空:max=q[0];
第3空:q[i*col+j]>max
第4空:max=q[i*col+j];
第5空:return max;
c++
输入:
3 5 -1 4
7 -32 0 9
-102 45 78 4
输出:
max=78 maxr=2 maxc=2
#include <stdio.h>
#define ROW 3
#define COL 4
int FindMaxbyCol(int *q,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 FindMaxbyCol(int *q,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=FindMaxbyCol(a[0],ROW,COL,&maxr,&maxc);
第2空:max=q[0];
第3空:q[i*col+j]>max
第4空:max=q[i*col+j];
第5空:return max;