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

很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;

}

posted @ 2019-10-20 20:31  熏五空--嵌入式  阅读(165)  评论(0编辑  收藏  举报