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

 
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂
 



Leave a Reply

avatar
  Subscribe  
Notify of