Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multiplying two integers, a and b, is actually done by adding the first number,

ID: 3710674 • Letter: M

Question

Multiplying two integers, a and b, is actually done by adding the first number, a, to itself b times.  

Dividing two numbers, a/b, is likewise actually done by subtracting the second number, b, from the first number, a, repeatedly until a is smaller than b (this is the remainder). The number of subtractions done is the number of times b goes into a.

Write two iterative methods, one for multiplication by addition and one for division by subtraction.

Write a recursive method that will multiply two numbers by adding the first to itself this way.

Write a second recursive method that will divide two numbers this way.

After testing all methods for accuracy, run the two multiply methods repeatedly, increasing the factors by a factor of ten until your program experiences failure. Quit running the method that failed, but continue running the method that did not fail, still increasing the factors by a power of ten until it, too, fails

Submit your code, and a written report discussing and detailing how each of the methods failed (what were the symptoms of failure) and what actually caused their failure.

Partial Pseudo-code:

In main

Create a loop so you can call your recursive and iterative methods lots of times and get a better picture of the performance difference.

Write a small driver that tests each of the four methods (exhaustively)

After testing, run a loop that

prompts for either the two multiply or the two divide methods

prompts for two integers

runs the selected methods

a * b

In multiply (recursive)

if a or b is zero

return zero

else

subtract 1 from b

return a + (multiply with new parameters)

a/b

In divide (recursive)

If b is zero, throw an exception

if a is less than b

return 0

else

subtract b from a

return 1 + (divide with new parameters)

** I have everything else i just need help with what is in bold **

Explanation / Answer

Hi Dear,

Please find my implementation.

Output:

Random numbers are: 61 43
Multiply Iterative: 2623
Multiply Recursive: 2623
Integer Division Iterative: 1
Integer Division Recursive: 1

Process finished with exit code 0