把指针作为函数参数的方法处理从大到小排序问题。

#include <iostream>
using namespace std;

void swap(int *p1,int *p2){
    int temp;
    temp=*p1;
    *p1=*p2;
    *p2=temp;
}


int main(){
    int a,b,*point1,*point2;
    cout<<"请输入两个整数。"<<endl;
    cin>>a>>b;
    point1=&a;b 
    ;point2=&b; 
    if(a<b){
        swap(point1,point2);
    }
    cout<<"max="<<a<<"  min="<<b<<endl;
    
    return 0;

}

 


  

posted @ 2017-12-25 18:34  羿龙  阅读(260)  评论(0编辑  收藏  举报