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

Decimal Addition Algorithm Explained

The document outlines a Modified Decimal Addition Algorithm for adding two positive numbers of different lengths. It describes a step-by-step process to handle the addition, including managing carry values and determining the final output format. The algorithm ensures that both numbers are processed correctly, regardless of their length, and provides a clear method for displaying the result.
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)
2 views1 page

Decimal Addition Algorithm Explained

The document outlines a Modified Decimal Addition Algorithm for adding two positive numbers of different lengths. It describes a step-by-step process to handle the addition, including managing carry values and determining the final output format. The algorithm ensures that both numbers are processed correctly, regardless of their length, and provides a clear method for displaying the result.
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 (Different

Lengths)

Given: m ≥ 1, n ≥ 1 where m may not be equal to n, and two positive numbers:


a_{m-1}a_{m-2}...a_0 and b_{n-1}b_{n-2}...b_0.

Wanted: c_k c_{k-1} ... c_0, where k = max(m, n).

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 k - 1 repeat Steps 4 through 6
Step 4: If i ≤ m - 1, let a_i = digit of a; otherwise set a_i = 0.
If i ≤ n - 1, let b_i = digit of b; otherwise set b_i = 0.
Add a_i + b_i + carry to get c.
Step 5: If c ≥ 10, then set c_i = c - 10 and carry = 1; otherwise, set c_i = c and carry = 0.
Step 6: Add 1 to i (move to next column).
Step 7: Set c_k = carry.
Step 8: If c_k = 1, then print c_k, c_{k-1}, ..., c_0; otherwise, print c_{k-1}, ..., c_0.
Step 9: Stop.

You might also like