表达式判断两个正整数大小
来源:互联网 发布:mac子弹头 编辑:程序博客网 时间:2024/06/14 15:40
// Exercise 2.5 Finding the largest of two integers without comparing them.#include <iostream>#include <ctime>#include <cstdlib>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); srand(time()); rand() cout << "\nThe larger integer is " << larger << "." << "\nThe smaller integer is " << smaller << ".\n"; return 0;}
如果a>b,则b/a=0,a/b!=0
long larger = (a*(a/b) + b*(b/a))/(a/b + b/a);
long smaller = (b*(a/b) + a*(b/a))/(a/b + b/a);
- 表达式判断两个正整数大小
- 判断两个数大小
- 两个数字判断大小
- 正则表达式判断身份证,邮箱,手机号码,正整数
- 判断两个字符串的大小
- 判断两个整数的大小
- 判断两个时间大小前后
- 判断两个数值的大小
- 判断两个整数的大小
- 正则表达式判断非零开头的正整数输入
- 用JS判断两个数字的大小
- 用JS判断两个数字的大小
- java 判断两个日期的大小
- js判断两个时间的大小
- JS判断两个时间的大小
- JS判断两个时间的大小
- javascript 判断两个日期的大小
- Java判断两个数字大小代码实例
- 线段树练习[单点更新] HDU 2795 Billboard
- 数据库clone完成后,sqlplus登录提示没有权限
- VE实战问题一:垫付客户运费问题的会计处理
- 最快的查出所有小字符串里的字母在大字符串里都有
- PL/SQL Developer自动补全SQL技巧
- 表达式判断两个正整数大小
- Java网络编程基础 InetAddress类的使用
- vs2010水晶报表问题,请各位高手帮帮忙,先谢谢了
- hibernate结合srping之getHibernateTemplate()的find方法使用
- 我的一些小功能备忘(会逐渐增加的!!)
- matlab basic
- JSON解析-详细
- Tomcat 7.0中使用自定义标签的问题
- C链表反转(时间复杂度O(n))