0% found this document useful (0 votes)
4 views1 page

Modified Decimal Addition Algorithm

The document outlines a modified decimal addition algorithm for adding two positive m-digit numbers. It details a step-by-step process to calculate the sum, accounting for carries when the sum of digits exceeds 9. The final result is printed based on whether there is a carry from the most significant digit.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Modified Decimal Addition Algorithm

The document outlines a modified decimal addition algorithm for adding two positive m-digit numbers. It details a step-by-step process to calculate the sum, accounting for carries when the sum of digits exceeds 9. The final result is printed based on whether there is a carry from the most significant digit.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like