Question: Solve in C programming language. Given two positive integers (a and b), their product can be computed using only mul- tiplication by two, division by
Solve in C programming language.

Given two positive integers (a and b), their product can be computed using only mul- tiplication by two, division by two, and addition, with the following algorithm: Write each number at the top of a column. Double the number in the first column (a), and halve the number in the second column (b). Ignore the remainder when dividing. If b is even, cross out the row. Continue to double and halve until the number in the second column is 1. Add up the remaining numbers (ie. those that have not been crossed out) in the first column. The total is the product of the original two numbers. For example, suppose that we want to compute the product of 39 and 82, the calcula- tions can be illustrated as follows: 39 32 78 41 156 20 312 10 5 1248 2 2496 1 3198 624 Hence we have a product of 3198. Write a C program to implement the above algorithm. Your program should ask the user to enter two non-negative integers. If the user enters one or two zero values, the correct product should be displayed without using the algorithm. If the user enters one or two negative values a message should be printed indicating that non-negative values should be entered. Sample output is given below. Note that only the rows that have not been crossed out need to be displayed. (Hint: add up the values to be included in the sum as they are calculated.) Sample input/output: 39 82 Computing product of 39 and 82... 78 41 624 5 2496 Product: 3198
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
