[SOLVED] CS 2400 Homework2 -Ancient Multiplication

25.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon hw2-kqvdbm.zip (18.3 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

An ancient method for multiplying two integers works by repeated multiplication and division by 2.  Let’s say you have two numbers (X and Y). Multiply X by 2 and divide (integer division) Y by 2.  Repeat the process until Y becomes zero and you can’t divide any further. The result of multiplying X by Y is the total of all the values of X whenever Y was odd.

Here is an example of multiplying 30 by 18:

X Y
30 18
60 9
120 4
240 2
480 1
  0

 

Result = 60 + 480 = 540.

Write a C++ program that repeatedly asks the user (y/n question) for two positive integers to multiply and uses the method outlined above to calculate and display the result of multiplication.  Validate the input values to make sure they are both positive. Your program should repeatedly ask the user to reenter each number until they enter a positive integer.

  • hw2-kqvdbm.zip