题目:输入3个数a,b,c,按大小顺序输出。
程序分析:利用指针方法。
程序代码:
#include<iostream>
using namespace std;
void Swap(int* p1, int* p2)
{
int temp = *p1;
* p1 = * p2;
* p2 = temp;
}
int main()
{
int a, b, c;
int* pa, * pb, * pc;
pa = &a;
pb = &b;
pc = &c;
cin >> a >> b >> c;
if (a > b)
Swap(pa, pb);
if (a > c)
Swap(pa, pc);
if (b > c)
Swap(pb, pc);
cout << a<<' ' << b<<' ' << c;
return 0;
}