面试题————不使用逻辑语句两个数值比较大小

很6,不知道啥原理,这大概就是数学的魅力吧。

#include <stdio.h>
#include <string.h>
#include<math.h>


int main()
{
int a=10,b=18;
int sun;
sun=(a+b+abs(a-b))/2;//     (两个数之和+两个数的差绝对值)除以2
printf("%d",sun);

return 0;

}

猜你喜欢

转载自www.cnblogs.com/qianrushi1/p/11709055.html