#include
void change(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
void exchange(int *q1,int *q2,int *q3)
{
if(*q1
if(*q1
if(*q2
}
void main()
{
int a,b,c,*p1,*p2,*p3;
printf("please enterthe numbers: ");
scanf("%d,%d,%d",&a,&b,&c);
p1=&a;
p2=&b;
p3=&c;
exchange(p1,p2,p3);
printf("\nmax=%d,mid=%d,min=%d\n",a,b,c);
system("pause");
}
使用指针对三个数进行排列。将指针变量p1指向变量a,p2指向b,p3指向c。然后调用函数,进行排列。如果q1所指向的变量的值小于q2指向的变量的值,则这两个变量的值交换,即假设q1指向a,q2指向变量b,*q1和*q2交换就是a的值和b的值交换。三组数两两交换,最后,a中是最大的数,b中是中间数,c中是最小的数。
最后添加暂停函数,否则程序运行就退出了。