1335 - C语言程序设计教程(第三版)课后习题10.1
输入三个整数,按由小到大的顺序输出。使用指针
Input
三个整数
Output
由小到大输出成一行,每个数字后面跟一个空格
Examples
Input
2 3 1
Output
1 2 3
Solution C++
#include<iostream> using namespace std; void swap(int *p,int *q) { int t=*p; *p=*q; *q=t; } int main() { int a,b,c; cin>>a>>b>>c; int *p1=&a,*p2=&b,*p3=&c; if (a>b) swap(p1,p2); if (a>c) swap(p1,p3); if (b>c) swap(p2,p3); cout<<*p1<<" "<<*p2<<" "<<*p3<<" "<<endl; return 0; }