How streamlined is this process? Goal: Compute for the product of two positive integers using the addition operation only.
Step 1: Request the first and second positive integers. Call them FirstNum and SecondNum, respectively. Step 2: Compare FirstNum with SecondNum. Call the lesser positive integer TotalCount; the greater positive integer, Term. Step 3: Set Sum to 0. Let Sum be the final answer to the addition operation. Step 4: Add Term to Sum. Step 5: Count the number of instances of Term in Sum. Call this CurrentCount. Step 6: Repeat Steps 4-5 until CurrentCount is equal to TotalCount. Step 7: Display Sum.
looks good to me instead of CurrentCount, you could just decrement TotalCount and stop once this hits zero.
By decrementing CurrentCount, do you mean subtracting from TotalCount after each time Step 4 is completed? How would this be more efficient than the current process?
It is only marginally more efficient in that it saves you declaring another variable. So after Step 4 you would do something like: TotalCount = TotalCount - 1
Join our real-time social learning platform and learn together with your friends!