Jun 8, 2009

Implement division (without using the divide operator, obviously).

int div(int n, int d)
{
if(n
return 1+div(n-d,d);
}

int div(int n, int d)
{
int i=0;
while(n>=d)
{
n=n-d;
i++;
}
return i;
}

No comments:

Post a Comment