编程实现两个正整数的除法,当然不能用除法操作符。
//编程实现两个正整数的除法,当然不能用除法操作符 int div(const int x, const int y) { int left_num = x; int result = 0; int multi; while (left_num >= y) //模拟小学学过的竖式除法运算 { multi = 1; while (y * multi <= (left_num >> 1)) { multi = multi << 1; } result += multi; left_num -= y * multi; } return result; }