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 the solution well 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 ≥ 1 and two positive numbers each containing m digits, a_1a_2...a_m and b_1b_2...b_m
Wanted: c_1c_2...c_m, where c_1c_2...c_m = a_1+a_2+...+a_m+b_1+b_2+...+b_m
Algorithm:
Step 1: Set the value of carry to 0
Step 2: Set the value of i to 0
Step 3: While the value of i is less than or equal to max(m, n), repeat the instructions in Steps 4 through 6
Step 4: Add the two digits a_i and b_i to the current value of carry to get c_i
Step 5: If c_i ≥ 10, then reset c_i to (c_i mod 10) and reset the value of carry to 1; otherwise, set the new value of carry to 0
Step 6: Add 1 to i, effectively moving one column to the left
Step 7: Set c_i to the value of carry
Step 8: Print out the final answer, c_1c_2...c_m
Step 9: Stop
Algorithm for adding two numbers with different number of digits