指针(三个数的交换)

#include<stdio.h>
swap(int *p1, int *p2){
        int temp;
        temp = *p1;
        *p1 = *p2;
        *p2 = temp;
}
exchange(int *ep1, int *ep2, int *ep3){
        if(*ep1<*ep2) swap(ep1,ep2);
        if(*ep1<*ep3) swap(ep1,ep3);
        if(*ep2<*ep3) swap(ep2,ep3);
}
main(){
        int a, b, c;
        int *pt1, *pt2, *pt3;
        scanf("%d,%d,%d", &a, &b, &c);
        pt1 = &a; pt2 = &b; pt3 = &c;
        exchange(pt1, pt2, pt3);
        printf("%d\n%d\n%d\n", a, b, c);
}

 

posted @ 2014-08-01 11:30  天道酬勤,坚持!  阅读(1147)  评论(0编辑  收藏  举报