面试题 16.07. 最大数值

面试题 16.07. 最大数值

编写一个方法,找出两个数字ab中最大的那一个。不得使用if-else或其他比较运算符。

示例:

输入: a = 1, b = 2
输出: 2

解题思路

 

 代码:

#include<math.h>

int maximum(int a, int b){
// double c = a;
        // double d = b;
        // int res = (int) ((Math.abs(c-d) + c + d)/2);
        // return res;

        long c = a;
        long d = b;
        int res = (int) ((fabs(c-d) + c + d)/2);
        return res;
}

 

posted @ 2020-08-22 19:54  多发Paper哈  阅读(79)  评论(0编辑  收藏  举报
Live2D