VOOZH about

URL: https://www.geeksforgeeks.org/dsa/multiply-number-10-without-using-multiplication-operator/

⇱ Multiply a number with 10 without using multiplication operator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Multiply a number with 10 without using multiplication operator

Last Updated : 11 Sep, 2023

Given a number, the task is to multiply it with 10 without using multiplication operator?
Examples: 
 

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. 


Output
500

Time Complexity: O(1)

Auxiliary Space: O(1)


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.
 

Output: 

500

Time Complexity: O(1)

Auxiliary Space: O(1)


 

Comment
Article Tags:
Article Tags: