Using reference variables as arguments
Write a function by using reference variables as arguments to sort two numbers in descending order.
#include <iostream>
using namespace std;
int swap(int &,int &);
int main(void)
{
int x,y;
cin >> x >> y;
swap(x,y);
cout << x << ' ' << y << endl;
return 0;
}
int swap(int &x,int &y)
{
int temp;
if(x<y)
{
temp=x;
x=y;
y=temp;
}
return 0;
}
评论