#include<stdio.h>
int main()
{
void max(int *p, int n);
void min(int *p, int n);
int a[10];
int i, n = 10, *p;
p = a;
printf("输入10个整数:\n");
for (i = 0;i < 10;i++)
{
scanf("%d", &a[i]);
}
max(a, n);
min(a, n);
for (i = 0;i < n;i++)
{
printf("%d ", a[i]);
}
printf("\n");
}
void max(int *p, int n)
{
int i, j, temp;
temp = *(p + 9);
for (i = 9;i >= 0;i--)
{
if (temp < *(p + i))
{
temp = *(p + i);
j = i;
}
}
*(p + j) = *(p + 9);
*(p + 9) = temp;
}
void min(int *p, int n)
{
int i, j, temp;
temp = *p;
j = 0;
for (i = 1;i < n;i++)
{
if (temp > *(p + i))
{
temp = *(p + i);
j = i;
}
}
*(p + j) = *p;
*p = temp;
}
|