编程实现两个正整数的除法,当然不能用除法操作符

#include<stdio.h>
int divid(int first, int second)
{
    int result = 0;
    int mul;
    while(first >= second)
    {
        mul = 1;
        while(2*mul*second <= first)
             mul = mul * 2;
        result += mul;
        first -= mul * second;
    }
    return result;
}
int main()
{
   int x = 10;
   int y = 2;
   int ret = divid(x, y);
   printf("%d\n", ret);
   return 0;
}

你可能感兴趣的:(编程实现两个正整数的除法,当然不能用除法操作符)