I want to find multiplication of two numbers in Java recursively using only addition, subtraction and comparison. So, I googled, and I found an Egyptian Algorithm that meets the requirements of the question.
However, I am not sure how to find the result of the multiplication after reaching the base case .
Example:
13 x 30 1 -- 30 2 -- 60 4 -- 120 8 -- 240 //we stop here because the double of 8 is larger than 13
To find the result, we add the numbers from the left column equal to 13, which they are 1+4+8 , and on the other hand we add its opposite numbers from the right column , which they are 30+120+240 = 390 , which is the result.
And now how to program the last part? how to check which numbers to add? I hope you guys understand my point. Hints are needed only.
source share