#include
#include
#include
#define N 5
#define M 2
int main()
{
int a[N];
int* p = a;
void input(int* p);
void exchange(int* p);
void output(int* p);
input(p);
exchange(p);
output(p);
}
void input(int* p)
{
int i;
printf("input the integer:");
for (i = 0; i < N; i++)
scanf("%d", p + i);
}
void exchange(int* p) //将最小的数与第一个数对换,把最大的数与最后一个数对换。
{
int i, *max = p, *min = p, temp; //<===========
for (i = 1; i < N; i++)
if (*(p + i) > *max)//<===========
max = (p + i);//<===========
else if (*(p + i) < *min)//<===========
min = (p + i);//<===========
temp = *p;
*p = *min;//<===========
*min = temp;//<===========
if (*max == *p)//<===========
max = min;
temp = *(p + N - 1);
*(p + N - 1) = *max;//<===========
*max = temp;//<===========
}
void output(int* p)
{
int i;
for (i = 0; i < N; i++)
printf("%5d", *(p + i));
}