#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define N 10
void InputArray(int* p, int m, int n);
int FindMax(int* p, int m, int n, int* pRow, int* pCol);
int main()
{
int m, n,max=0;
printf("Input m, n:");
scanf("%d,%d", &m, &n);
int num[N][N];
printf("Input %d*%d array:\n", m, n);
InputArray(*num, m, n);
int Row=0;int Col=0;
max=FindMax(*num, m, n, &Row, &Col);
printf("max = %d, row = %d, col = %d\n", max, Row, Col);
}
void InputArray(int* p, int m, int n)
{
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf_s("%d", &p[i * n + j]);
}
}
printf("\n");
}
int FindMax(int* p, int m, int n, int* pRow, int* pCol)
{
int i=0, j=0, temp;
temp = p[*pRow * n + *pCol];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
if (p[i * n + j] > temp || p[i * n + j] == temp)
{
temp = p[i * n + j];
*pRow = i;
*pCol = j;
}
}
}
return temp;
}
按如下函数原型编程从键盘输入一个m行n列的二维数组,然后计算数组中元素的最大值及其所在的行列下标值。其中,m和n的值由用户键盘输入。已知m和n的值都不超过10。void InputArray(int
最新推荐文章于 2022-12-05 14:17:42 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)