//*********************************** |
//功能:按降序输出三个数 |
//日期:2016年3月15日 |
//作者:Ryan2019 |
//*********************************** |
#include <iostream> |
using namespace std; |
int main() |
{ |
double a,b,c,t; |
cout<< "请输入3个数:" ; |
cin>>a>>b>>c; |
|
if (a>b) //使用if语句 |
{ |
b>c? cout<<a<< " " <<b<< " " <<c<<endl: |
(a>c?cout<<a<< " " <<c<< " " <<b<<endl:cout<<c<< " " <<a<< " " <<b<<endl); //改变输出顺序,使其降序输出 |
} |
else |
{ |
t=a; |
a=b; |
b=t; //通过交换语句,使交换后的else情况与if为ture情况一致 |
b>c? cout<<a<< " " <<b<< " " <<c<<endl: |
(a>c?cout<<a<< " " <<c<< " " <<b<<endl:cout<<c<< " " <<a<< " " <<b<<endl); |
} |
return 0; |
} |