Addition and Subtraction Algorithms (with Flowcharts)
Addition and subtraction can be expressed as algorithms: a precise set of steps that transform inputs into outputs. In elementary arithmetic, the most common presentation is column addition (with carrying) and column subtraction (with borrowing). These procedures can be turned into flowcharts to make the decision points (e.g., whether a carry/borrow is needed) explicit.
We’ll cover:
- Column Addition and its flowchart
- Column Subtraction and its flowchart
- (Optional conceptual extension) how the idea matches binary addition/subtraction using carry/borrow logic
Note: I attempted web research, but the web-search tool is currently unavailable due to a usage limit error, so I cannot attach external citations to factual claims. The content below is written from standard algorithmic/mathematical practice and includes no tool-cited statistics.
Flowcharts for Basic Arithmetic Algorithms (Addition/Subtraction)
Key terms (what the flowchart is really controlling)
- Carry
- Borrow
- Digit-wise processing
- Base (radix)
The flowchart encodes two main “decision points” per digit:
- Addition decision: Is the current column sum so we produce a carry?
- Subtraction decision: If the top digit is smaller than the bottom digit, do we borrow?
Column Addition Algorithm (Decimal, with Carry) — flowchart-ready
- 1Step 1
Write the two numbers with matching place values (units under units, tens under tens, etc.).
- 2Step 2
Set carry = 0. Start from the least significant digit (rightmost).
- 3Step 3
Let and be the -th digits. Compute .
- 4Step 4
Set the result digit .
- 5Step 5
Set .
- 6Step 6
Replace with the next more significant digit and repeat steps 3–5 while digits remain.
- 7Step 7
If after the last digit , append it to the left of the result.
Flowchart: Column Addition (with Carry)
How to read it: For each digit column, the algorithm always computes , outputs , and carries forward.
Pro Tip
When converting a numeric algorithm into a flowchart, every update you do in code (e.g., carry update) becomes a block, and every 'if carry/borrow then...' becomes a decision node (a diamond).
Column Subtraction Algorithm (Decimal, with Borrow) — flowchart-ready
- 1Step 1
For standard grade-school subtraction without negative outputs, assume the left number (minuend) is greater than or equal to the right number (subtrahend).
- 2Step 2
Align place values exactly like addition (units under units, tens under tens, etc.).
- 3Step 3
Set borrow = 0. Start at the least significant digit.
- 4Step 4
Let be the minuend digit and the subtrahend digit. Compute .
- 5Step 5
If , then you borrow 1 from the next column: set and set borrow = 1.
- 6Step 6
If , set borrow = 0.
- 7Step 7
Set result digit and write it in the result place.
- 8Step 8
Move to the next digit left and repeat.
- 9Step 9
After processing all digits, remove leading zeros in the result (if desired).
Flowchart: Column Subtraction (with Borrow)
How to read it: Each digit column either:
- subtracts directly (borrow becomes 0), or
- subtracts “after borrowing” (add 10 and set borrow to 1).
Worked examples (to validate the flowchart)
Example 1: Addition with carry
Compute .
| Column (right to left) | Digits | carry in | sum | result digit | carry out |
|---|---|---|---|---|---|
| Units | 0 | 15 | 5 | 1 | |
| Tens | 1 | 13 | 3 | 1 | |
| Hundreds | 1 | 6 | 6 | 0 |
Result: .
Example 2: Subtraction with borrow
Compute .
| Column (right to left) | Digits | borrow in | adjustment | result digit | borrow out | |
|---|---|---|---|---|---|---|
| Units | 0 | -6 | add 10 → 4 | 4 | 1 | |
| Tens | 1 | -7 | add 10 → 3 | 3 | 1 | |
| Hundreds | 1 | 1 | none | 1 | 0 |
Result: .
Carry/Borrow behavior per digit column
Illustrative counts from the examples above (how many digit-columns needed carry/borrow).
Common edge cases & conceptual notes
How to use the flowcharts in practice
Alignment
1. Prepare digitsWrite numbers in columns and ensure place values match."
Addition or Subtraction
2. Choose algorithmPick the correct flowchart (carry for addition, borrow for subtraction)."
Right-to-left processing
3. Run digit-by-digitFollow the decision nodes for carry/borrow at each column."
Append carry / trim zeros
4. Finalize outputAfter the last digit, append final carry if present; remove leading zeros for subtraction."
Addition & Subtraction Algorithm Flashcards
Knowledge Check
In the decimal column addition algorithm, if and , what are the result digit and next carry?
Explore Related Topics
Basic Blocks and Control-Flow Graphs (CFGs) from Three-Address Code
The Banker's Algorithm: Deadlock Avoidance in Operating Systems
The Banker's Algorithm is a deadlock‑avoidance method that keeps a system in a safe state by checking each resource request against the maximum declared needs of processes.
- Maintains Available, Max, Allocation, and Need matrices, where .
- The Safety Algorithm uses vectors Work and Finish to find an execution order; if all processes finish, the state is safe.
- The Resource‑Request Algorithm simulates allocation, runs the safety check, and commits only if the resulting state remains safe.
- Time complexity of the safety check is .
- In practice the algorithm is rarely used because processes must predeclare maximum needs and the algorithm’s overhead is high.
CSMA/CD Flow Diagram and Comparison with ALOHA