首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求最简单的两数比大小的算法,该如何处理

2012-03-08 
求最简单的两数比大小的算法RT,题目的要求是不用中间变量,只比较一次,然后按照:the smaller is :...the la

求最简单的两数比大小的算法
RT,题目的要求是不用中间变量,只比较一次,然后按照:
the smaller is :...
the larger is :..
进行输出。
求最简单的算法,整数浮点数都可以比较
 C或者C++都可以,最好C++
求大牛赐教

[解决办法]
只比较一次可以这样
#include<iostream>

using namespace std;


int main()
{
int a,b;
cin>>a>>b;
a<b?(cout<<"the smaller is :"<<a<<endl<<"the larger is "<<b):(cout<<"small is"<<b<<endl<<"bigger is "<<a);
system("pause");
return 0;
}

热点排行