问题及代码:
<pre class="cpp" name="code">/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:李尚泽
* 完成日期:2014年12月23日
* 版 本 号:v1.0
*
* 问题描述:输入3个整数,将其按从大到小的顺序输出
*/
#include <iostream>
using namespace std;
int main()
{
void exchange(int*,int*,int*);
int a,b,c,*p1,*p2,*p3;
cin>>a>>b>>c;
p1=&a;
p2=&b;
p3=&c;
exchange(p1,p2,p3);
cout<<a<<" "<<b<<" "<<c<<endl;
}
void exchange(int*p1,int*p2,int*p3)
{
void swap(int*,int*);
if(*p1<*p2)
swap(p1,p2);
if(*p1<*p3)
swap(p1,p3);
if(*p2<*p3)
swap(p2,p3);
}
void swap(int*x,int*y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
运行结果: