输入:
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 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]);
}
2分
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;
2分
*maxRow=0;
*maxCcol=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(2分
)
{
2分
*maxRow=i;
*maxCcol=j;
}
}
}
2分
}
(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
完整代码及各个位置填空标注如下:
#include <stdio.h>
#define ROW 3
#define COL 4
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]);
}
max = FindMaxbyRow(a, ROW, COL, &maxr, &maxc); //(1)
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;
max = p[0][0]; //(2)
*maxRow = 0;
*maxCcol = 0;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (p[i][j]>max) //(3)
{
max = p[i][j]; //(4)
*maxRow = i;
*maxCcol = j;
}
}
}
return max; //(5)
}
是每个分值的地方填空么?
#include <stdio.h>
#define ROW 3
#define COL 4
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]);
}
max = FindMaxbyRow(a,ROW,COL,&maxr,&maxc);
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;
max = p[0][0];
*maxRow=0;
*maxCcol=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(p[i][j] > max)
{
max = p[i][j];
*maxRow=i;
*maxCcol=j;
}
}
}
return max;
}