找出较大的一个数

来源:互联网 发布:软件编程代码 编辑:程序博客网 时间:2024/04/30 14:15

There are two int variables : a and b , don't use "if","? :","switch" or other judgement statements , find out the biggest one of the two numbers.

 

 

max = ((a+b)+|a-b|)/2;

 

当a>=b时,|a-b|为a-b,max=(a+b+a-b)/2=a;

当a<b时,|a-b|为-(a-b),max=(a+b-a+b)/2=b;