#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void changeArrayData(int *arrayAddress1, int *arrayAddress2);
int main( void)
{
int array[5][5] = {0};
int i = 0, j = 0;
int *arrayMax = 0, *arrayMin[4] = {array[0], array[0]+4, array[4], array[4]+4};
int temp = 0;
/*给数组赋值*/
srand((unsigned long)time(0));
while(i <25)
*(*array + i++) = rand()%100;//100以内的
随机数i = 0;
arrayMax = array[0];
while(++i < 25)
{
if(*(*array + i) > *arrayMax)//找最大值
arrayMax = *array + i;
if(*arrayMin[0] > *(*array + i))//最小值
arrayMin[0] = *array + i;
}
if(arrayMax != array[2] + 2)
{
changeArrayData(arrayMax, array[2] + 2);
arrayMax = array[2] + 2;
}//交换最大值
if(arrayMin[0] != array[0])
{
changeArrayData(arrayMin[0], array[0]);
arrayMin[0] = array[0];
}//交换最小值
i = 1;
while(i < 25)
{
for(j = 1; j < 4; j++)
if(*(*array+i) < *arrayMin[j] && *(*array+i) >= *arrayMin[j-1])//*(*array+i)的值要比*arrayMin[j]小,但不能比*arrayMin[j-1]小
changeArrayData(*array+i, arrayMin[j]);
i++;
}
/*输出*/
for(i = 0; i < 5; i++)
{
for(j = 0; j < 5; j++)
printf("%2d ", array[i][j]);
printf("\n");
}
return 0;
}
/******************************************************
函数功能: 交换两个整形地址单元的值
******************************************************/
void changeArrayData(int *arrayAddress1, int *arrayAddress2)
{
int temp = 0;
temp = *arrayAddress1;
*arrayAddress1 = *arrayAddress2;
*arrayAddress2 = temp;
}