如题所述
#include <stdio.h>
#include <stdlib.h>
#define COL 5
#define ROW 6
int *rowPoint(int (*p)[COL], int *max)
{
int temp = **p;
static int arr[2];
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
if (*(*(p + i) + j) > temp)
{
temp = *(*(p + i) + j);
arr[0] = i;
arr[1] = j;
}
}
}
*max = temp;
return arr;
}
int *colPoint(int *p, int *max)
{
static int arr[2];
int temp = *p;
int i = 0;
for (int *s = p; s < p + (COL * ROW); s++)
{
if (temp < *s)
{
temp = *s;
arr[1] = i % COL;
arr[0] = (i - arr[i]) / COL;
}
i++;
}
*max = temp;
return arr;
}
int main()
{
int arr[ROW][COL] =
{99, 88, 100, 58, 150,
98, 63, 56, 17, 89,
12, 160, 63, 89, 75,
52, 20, 158, 963, 789,
852, 985, 510, 101, 102,
753, 951, 654, 742, 168};
printf("元素值为:\n");
for (int i = 0; i < ROW; i++)
{
for (int j = 0; j < COL; j++)
{
printf("%d\t", arr[i][j]);
}
printf("\n");
}
int max;
int *result = (int *)malloc(sizeof(int) * 2);
result = rowPoint(arr, &max);
printf("\n行指针结果:\n");
printf("max:%d 下标:%d,%d %d行%d列\n", max, result[0], result[1], result[0] + 1, result[1] + 1);
result = colPoint(arr[0], &max);
printf("列指针结果:\n");
printf("max:%d 下标:%d,%d %d行%d列\n", max, result[0], result[1], result[0] + 1, result[1] + 1);
return 0;
}