如下整型2维数组,大小为MXN,要求找出其中最大值的所在的行和列以及该最大值?怎么实现?

要求如下
(1)以数组名和数组大小为该函数的形参
(2)数组元素的值在MAIN函数中输入,结果在函数MAX中输出

蝴蝶不菲
浏览 187回答 1
1回答

猛跑小猪

其实比较简单啦, 就是找最大值, 然后记下它所在的位置就可以了~~详细代码如下:#include <stdio.h>#define M 30#define N 30void 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;}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP