Perform Division of two numbers without using division operator (/)

Write an program to perform division of two numbers without using division operator (‘/’).

 
 

Approach #1. Division Using Repeated Subtraction

We know that divisions can be solved by repeatedly subtracting the divisor from the dividend till the dividend becomes less than the divisor. The number of times the repeated subtraction is carried out is equal to the quotient.

 

Download   Run Code

Output:

Remainder is 1
Quotient is -3

 

Below is the recursive version of above program:

 

Download   Run Code

Output:

Remainder is 1
Quotient is -3

 

Approach #2

 

Download   Run Code

Output:

Remainder is 1
Quotient is -3

 

Approach #3. Division Using Binary Operator

This approach is inpired by this answer in stackoverflow.

 

Download   Run Code

Output:

Remainder is 1
Quotient is -3

 
Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Leave a Reply

Notify of
avatar
wpDiscuz