Solve given set of problems without using multiplication or division operators

In this post we will discuss few related problems that can be solved without using multiplication and division operators.


 

Problem 1. Multiply a given integer with 15 without using multiplication and division operators.

The idea is to use left shift Bitwise operator to solve this problem. Let the given integer be n. We know that 15n can be rewritten as

We can extend this solution to any number of the form 2^i – 1 where i >= 1 and we can use below expression:

 

Another approach:

15n can also be rewritten as –

 

 

Problem 2. Multiply a given even integer with 7.5 without using multiplication and division operators.

We know that 7.5n can also be rewritten as 15n/2. We can easily use expressions used in problem 1 to solve this problem as well.

OR

 

Another approach:

7.5n can also be rewritten as –

Please note that if n is odd, above expression will return ceil of the result. Instead, we can use below expression to return floor

Please note that above solutions are prone to overflow as we’re using left shift operator.
 

 

Problem 3. Calculate value of 15n/16 without using multiplication and division operators.

Like problem 2, we can easily use expressions used in problem 1 to solve this problem as well.

OR

 

Another approach:

15n/16 can also be rewritten as –

Note that first two expressions are equivalent to (15*n)/16 but last expression is equivalent to 15*(n/16). So, results can differ in both.

 
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