【发布时间】:2011-01-25 21:54:28
【问题描述】:
可能重复:
Find the maximum of two numbers without using if-else or any other comparison operator
更大:
if x > y then return 1, else return 0
例子:
- isGreater(4,5) = 0
- isGreater(5,4) = 1
合法运营商:! ~ & ^ | + << >>
isGreater 是函数..
我试过了:
int isGreater(int x, int y) {
return (y+(~x+1)) >> 31 & 1;
}
但不工作.. :(( 让我知道我还能做什么?
【问题讨论】:
-
“我如何用 C 运算符的一些有限子集做 X?”的源源不断的流是怎么回事?输入问题?
-
第 1 步。请使用
{}按钮格式化您的代码。第 2 步。请用 [homework] 标签标记您的作业。 -
@Oli,显然这是一个常见的家庭作业。
-
标题说“两个数字的最大值”,而问题本身表明您只想测试
x > y- 这是它??? -
这是一个合理的家庭作业数学课,而不是编程课。
标签: c