Given a number, the task is to multiply it with 10 without using multiplication operator?
Input : n = 50 Output: 500 // multiplication of 50 with 10 is = 500 Input : n = 16 Output: 160 // multiplication of 16 with 10 is = 160
A simple solution for this problem is to run a loop and add n with itself 10 times. Here we need to perform 10 operations.
A better solution is to use bit manipulation. We have to multiply n with 10 i.e; n*10, we can write this as n*(2+8) = n*2 + n*8 and since we are not allowed to use multiplication operator we can do this using left shift bitwise operator. So n*10 = n<<1 + n<<3.
This article is contributed by Shashank Mishra ( Gullu ). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Efficient way to multiply with 7
- Write an Efficient Method to Check if a Number is Multiple of 3
- Find the Number Occurring Odd Number of Times
- Write an Efficient C Program to Reverse Bits of a Number
- Count number of bits to be flipped to convert A to B
- Rotate bits of a number
- Compute modulus division by a power-of-2-number
- Find whether a given number is a power of 4 or not
- Add 1 to a given number
- Multiply a given Integer with 3.5
- Next higher number with same number of set bits
- Program to count number of set bits in an (big) array
- Swap bits in a given number
- Binary representation of a given number
- Russian Peasant (Multiply two numbers using bitwise operators)