What happens if you add a 5-digit number to a 3-digit number. Do our steps handle this situation correctly?
The World of Algorithms · Question 2 of 15
What happens if you add a 5-digit number to a 3-digit number. Do our steps handle this situation correctly?
Take 48765 + 734. Aligned from right to left, the 3-digit number has no digits in the thousands and ten thousands columns.
| Column | Digits | Carry in | Sum | Write | Carry out |
|---|---|---|---|---|---|
| units | 5 + 4 | 0 | 9 | 9 | 0 |
| tens | 6 + 3 | 0 | 9 | 9 | 0 |
| hundreds | 7 + 7 | 0 | 14 | 4 | 1 |
| thousands | 8 + (no digit) | 1 | 9 | 9 | 0 |
| ten thousands | 4 + (no digit) | 0 | 4 | 4 | 0 |
Units: , write 9, carry 0. Tens: , write 9, carry 0. Hundreds: , write 4, carry 1.
Thousands: Step 3 says "add the two digits and the current value of carry", but there is only one digit, 8. We must treat the missing digit as 0: , write 9, carry 0.
Ten thousands: again only one digit, , write 4.
So , which is correct.
Do the steps handle this correctly? Only if we make an assumption the steps do not state. Step 3 speaks of "the two digits", and Step 4 says to repeat "until there are no more digits on the left", which does not make clear whether it means no more digits in either number or in both. If we stopped when the shorter number ran out, we would get only 499, which is wrong; and we would also have no rule for a carry going into a column that has just one digit.
The steps work correctly if we add the rule: if one number has no digit in a column, take that digit to be 0 (equivalently, write 734 as 00734), and repeat Step 3 until both numbers have no more digits on the left.
