c++输入3个整数,调用函数按由小到大的顺序输出

任务描述:

输入3个整数,按由小到大的顺序输出(要求用指针或引用方法处理)

测试输入:

4 91 51

预期输出:

4 51 91

程序源码:

#include <stdio.h>
#include <iostream>
using namespace std;

void sort(int &a,int &b,int &c)
{
    int temp;
    if(a>b)
    {
        temp=a;
        a=b;
        b=temp;
    }

    if(a>c)
    {
        temp=a;
        a=c;
        c=temp;
    }
    
    if(b>c)
    {
        temp=b;
        b=c;
        c=temp;
    }
    

}
int main()
{
    
    // 请在此添加代码
    /********** Begin *********/
    int  a,b,c;
    cin>>a>>b>>c;
    sort(a,b,c);
    cout<<a<<" "<<b<<' '<<c;
    
    
    /********** End **********/
    return 0;
}