zoukankan      html  css  js  c++  java
  • 微软面试题:编程实现两个正整数的除法

    编程实现两个正整数的除法,当然不能用除法操作符。
    // return x/y.
    int div(const int x, const int y) {
    ....
    }

    // return x/y
    
    int div(const int x, const int y) {
    int left_num = x;
    int result = 0;
    while (left_num >= y) {
        int multi = 1;
        while (y * multi <= (left_num >> 1)) {
           multi = multi << 1;
        }
        result += multi;
        left_num -= y * multi;
    }
    return result;
    }
    
    扩展问题:
    如果需要测试上面这个函数,需要哪些测试用例?
  • 相关阅读:
    COM组件
    【游戏引擎架构】入门(一)
    UNICODE字符串
    Python随笔10
    Python随笔9-函数
    Python随笔7
    Python随笔6
    Python随笔5
    Python随笔4
    Python随笔3
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2414380.html
Copyright © 2011-2022 走看看