第一章 课后习题 10

Posted on 2017-09-10 14:38  dragonliu欧美  阅读(165)  评论(1编辑  收藏  举报
 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 { void sort(int x,int y,int z);
 5   int x,y,z;
 6   cin>>x>>y>>z;
 7   sort(x,y,z);
 8   return 0;
 9 }
10 void sort(int x,int y,int z)
11 {
12   int temp;
13   if(x>y) {temp=x;x=y;y=temp;}   //{ }内3个语句的作用是将x和y的值互换)
14   if(z<x) cout<<z<<','<<x<<','<<y<<endl;
15     else if (z<y) cout<<x<<','<<z<<','<<y<<endl;
16       else cout<<x<<','<<y<<','<<z<<endl;