1 回答
TA贡献1858条经验 获得超8个赞
其实比较简单啦, 就是找最大值, 然后记下它所在的位置就可以了~~
详细代码如下:
#include <stdio.h>
#define M 30
#define N 30
void MAX(int a[M][N], int row, int column)
{
int i = 0, j = 0;
int (*p)[N] = a;
int max = **p;
int max_row = 0, max_column = 0;
for (i = 0; i < row; i++)
{
for (j = 0; j < column; j++)
{
if (*(*(p + i) + j) > max)
{
max = *(*(p + i) + j);
max_row = i;
max_column = j;
}
}
}
printf("The max of array is array[%d][%d]\n", max_row, max_column);
printf("Tt is in row %d, column %d\n", max_row, max_column);
}
int main()
{
int i = 0, j = 0;
int array[M][N] = {0};
int row = 0, column = 0;
printf("Please input the row of array: \n");
scanf("%d", &row);
printf("Please input the column of array: \n");
scanf("%d", &column);
printf("Please input a array: \n");
for (i = 0; i < row; i++)
{
for (j = 0; j < column; j++)
{
scanf("%d", &array[i][j]);
}
}
MAX(array, row, column);
return 0;
}
- 1 回答
- 0 关注
- 186 浏览
添加回答
举报