Modified Decimal Addition Algorithm
Given: m ≥ 1 and two positive numbers each containing m digits,
a_{m-1}a_{m-2}...a_0 and b_{m-1}b_{m-2}...b_0
Wanted: c_m c_{m-1}c_{m-2}...c_0 where
(a_{m-1}a_{m-2}...a_0) + (b_{m-1}b_{m-2}...b_0) = (c_m c_{m-1}c_{m-2}...c_0)
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 m - 1 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
Step 5: If c ≥ 10, then reset c_i = c - 10 and reset the value of carry to 1; otherwise, set c_i = c and reset
carry to 0
Step 6: Add 1 to i, effectively moving one column to the left
Step 7: Set c_m = carry
Step 8: If c_m = 1, then print c_m, c_{m-1}, c_{m-2}, ... c_0; otherwise, print c_{m-1}, c_{m-2}, ... c_0
Step 9: Stop