C++——输入3个整数,按由小到大的顺序输出。用指针或引用方法处理

没注释的源代码

#include <iostream>

using namespace std;
void swap(int *p1,int *p2);
int main()
{
    int a,b,c,*p1,*p2,*p3;
    cout<<"please input int a,b,c:";
    cin>>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);
    cout<<"now the order is:"<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}
void swap(int *p1,int *p2)
{
    int temp;
    temp=*p1;
    *p1=*p2;
    *p2=temp;
}
 

猜你喜欢

转载自blog.csdn.net/2303_80770781/article/details/143268019