Question: Modify the decimal addition algorithm of Figure 1.2 so that the two numbers being added do not have to have the same number of digits.
Modify the decimal addition algorithm of Figure 1.2 so that the two numbers being added do not have to have the same number of digits. That is, the algorithm should be able to add a value a containing m digits to a value b containing n digits, where m may or may not be equal to n.
PLEASE, explain well the solution because I really can't seem to understand the question or even the addition algorithm and how it works.
Thank you!
FIGURE 1.2 Given: m 2 1 and two positive numbers each c m digits, aa and Algorithm: Step 1 Set the value of carry to 0 Step 2Set the value of i to 0 Step 3 While the value of i is less than or equal to m 1, repeat the instructions in Steps 4 through 6 Step 4 Step 5 Add the two digits a, and b,to the current value of carry to get c If c 10, then reset c to ( 10) and reset the value of carry to 1; otherwise, set the new value of carry to 0 Add 1 to i, effectively moving one column to the left Step 6 Step 7 Set c to the value of carry Step 8 Print out the final answer, cmG,-|G,4",do Step9 Stop Algorithm for adding two m-digit numbers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
