编程实现两个正整数的除法,当然不能用除法操作符。
// 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; } 扩展问题: 如果需要测试上面这个函数,需要哪些测试用例?

相关文章:

  • 2021-07-22
  • 2021-10-27
  • 2022-12-23
  • 2021-06-10
  • 2021-08-28
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-10-28
  • 2022-01-06
相关资源
相似解决方案