编写c++程序,完成如下功能

来源:百度知道 编辑:UC知道 时间:2024/05/18 09:58:25
1.从键盘输入3个整数,分别存放在变量a.b.c中。
2.设计一个函数,将3个整数按从小到大的次序存放到变量a.b.c中。
3.使用引用传递参数。
4.依次输出变量a.b.c。

#include<iostream.h>
using namespace std;

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

void main()
{
int a,b,c;
cout<<"Input 3 numbers:"<<endl;
cin>>a>>b>>c;
sort(a,b,c);
cout<<"a:"<<a<<" b:"<<b<<" c:"<<c;
}