对3个变量由大到小顺序排序,要求使用变量的引用。
代码如下:
#include<iostream>
using namespace std;
void paixu(int &a,int &b,int &c);
void p(int &x,int &y);
int main()
{
int a,b,c;
cin>>a>>b>>c;
paixu(a,b,c);
cout<<a<<endl<<b<<endl<<c<<endl;
return 0;
}
void paixu(int &a,int &b,int &c)
{
if(a>b)
p(a,b);
if(a>c)
p(a,c);
if(b>c)
p(b,c);
}
void p(int &x,int &y)
{
int t;
t=x;
x=y;
y=t;
}