您的位置:首页 > 其它

不用判断语句实现两个整数的比较

2009-07-06 15:47 330 查看
#include <iostream>
using std::cin;
using std::cout;
int main() {
long a = 0L;
long b = 0L;
cout << "Enter a positive integer: ";
cin >> a;
cout << "Enter another different positive integer: ";
cin >> b;
// The trick is to find arithmetic expressions for each of the larger
// and the smaller of the two integers
long larger = (a*(a/b) + b*(b/a))/(a/b + b/a);
long smaller = (b*(a/b) + a*(b/a))/(a/b + b/a);
cout << "/nThe larger integer is " << larger << "."
<< "/nThe smaller integer is " << smaller << "./n";
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐