#include<stdio.h>
void swap(int* x, int* y, int* z)
{
if (*x > *y)
{
int t = *x;
*x = *y;
*y = t;
}
if (*x > *z)
{
int t = *x;
*x = *z;
*z = t;
}
if (*y > *z)
{
int t = *y;
*y = *z;
*z = t;
}
printf("%d %d %d\n", *x, *y, *z);
}
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
int* p1 = &a, *p2 = &b, *p3 = &c;
swap(p1, p2, p3);
return 0;
} 2018-09-25程序
8-1输入3个整数按从小到大的顺序输出
int main()
{
void swap(int p1,int p2);
int a,b,c;
int p1, p2, p3;
printf("please input three integer:");
scanf("%d,%d,%d",&a,&b,&c); p1=&a;
p2=&b;
p3=&c;
if(a>b) swap(p1,p2);
if(a>c) swap(p1,p3);
if(b>c) swap(p2,p3);
printf("now the order is %d,%d,%d\n",a,b,c);
return 0;
}
void swap(int p1,int p2) {
int temp;
temp=p1;p1=p2;*p2=temp;
}