How will you multiply two numbers without using the "*" and bitwise operations in an efficient way?(Just by using operators like +,-,/).
Asked
Active
Viewed 1,925 times
-2
-
Take a look at http://stackoverflow.com/questions/2069488/how-can-i-perform-multiplication-without-the-operator – David Apr 10 '13 at 09:53
2 Answers
1
a*b == 10^(Log(a*b)) == 10^(Log(a) + Log(b)) == exp(ln(a) + ln(b))
where ^
means exponentiation and Log
is the logarithm with a base of 10

halex
- 16,253
- 5
- 58
- 67
0
multiply(a,b):
if(a==0) return 0
r<-0
while(b/a!=r) r++
return r
Ok, I'm kidding, but you should give more informations about your search: what is an efficient way for you? Can you give an approximation of the complexity searched? Or do you want the most efficient algorithm? Because, if you don't precise anything, I can answer too:
multiply(a,b):
r<-0
while(a!=0)
r<-r+b
b<-b-1
return r

Alexis Comte
- 81
- 1
- 6
-
What's the point of the first code sample (which seems to do division)? – Bernhard Barker Apr 10 '13 at 10:02