Implement a division algorithm in your favourite language which handles integer division. It need only handle positive numbers - but bonus points if it handles negative and mixed-sign division, too. Results are rounded down for fractional results.
The program may not contain the /
, \
, div
or similar operators. It must be a routine which does not use native division capabilities of the language.
You only need to handle up to 32-bit division. Using repeated subtraction is not allowed.
Input
Take two inputs on stdin separated by new lines or spaces (your choice)
740
2
Output
In this case, the output would be 370
.
The solution which is the shortest wins.
740,2
also permitted for the input? ie comma separated? \$\endgroup\$0.142857
... or0
. \$\endgroup\$dividend / divisor
. Some programming languages also provide the division operation with reversed operands, sodividend / divisor = divisor \ dividend
. This is what Thomas wanted to exclude. \$\endgroup\$