0

I faced a guestion to implement division without using divide and Comparison Operators such as <, > ==, etc. Also, bit wise operation are not allowed. I can use loop, sub, add, ...

There is one condition that I think it is important: There is no negative value and a negative value resulted during the process is considered as zero. I think without this condition it is impossible to implement that.

1 Answers1

0

Assume that there is no negative values. Only use assign, loop, increment, sub, add.

Div(A, B) {

   temp = 1; 
   result = -1;

   loop(A) {
       temp = 0;
       increment(result)
       A = sub(A, B)
   }

   return add(result, temp);
}
user3601784
  • 377
  • 1
  • 9