#define ROWS
2
#define COLS
3
#define COUNT
ROWS * COLS
int max, min, max_index, min_index, i, t;
scanf("%d", &t);
max = min = t;
max_index = min_index = 0;
for(i = 1; i < COUNT; i++)
{
scanf("%d", &t);
if(max < t){ max = t; max_index = i;}
else if(min > t){ min = t; min_index = i;}
}
printf("max is a[%d][%d] = %d\nmin is a[%d][%d] = %d\n", max_index / COLS, max_index % COLS, max, min_index / COLS, min_index % COLS, min);
这段代码可以输出你想要尺寸的数组中的最大值、最小值,以及它们的下标。