用引用作函数参数的方法,在函数中对3个数进行排序。主函数中的变量为a,b,c, 从键盘输入数据,调用函数后,在主函数中按a,b,c的顺序打印,而且是从大到小排列的。
參考答案:#include<iostream.h>
int max(int a, int b)
{
return a > b ? a : b;
}
void MAX(int& a, int& b, int& c)
{
int temp;
temp = max(a,b);
cout << max(temp,c) << endl;
cout << temp << endl;
if (temp == a) {
cout << b << endl;
}
else
{
cout << a << endl;
}
}
void main()
{
int a = 4, b = 5, c = 6;
MAX(a, b, c);
}