## Invitation to Computer Science 8th Edition

Given: Two positive m-digit numbers $a_{m} a_{m-1} \ldots a_{1}$ and $b_{m} b_{m-1} \ldots b_{1}$ where $a_{m} a_{m-1} \ldots a_{1} \geq b_{m} b_{m-1} \ldots b_{1}$ Wanted: $c_{m} c_{m-1} \ldots c_{1}$ which is equal to $a_{m} a_{m-1} \ldots a_{1}-b_{m} b_{m-1} \ldots b_{1}$ Step 1 Set the value of borrow to 0 Step 2 Set the value of $i$ to 1 Step 3 While the $i \leq(m)$ perform Steps 4 through 7 Step 4 Set value of $a_{i}$ to $a_{i}-$borrow Step 5 If $a_{i} \geq b_{i}$ then $c_{i}=a_{i}-b_{i}$ and set borrow $=0$ Step 6 Otherwise, $c_{i}=10-\left(b_{i}-a_{i}\right)$ and set borrow $=1$ Step 7 Add 1 to $i$ Step 8 Print the answer $c_{m} c_{m-1} \ldots c_{1}$ Step 9 Stop
Given: Two positive m-digit numbers $a_{m} a_{m-1} \ldots a_{1}$ and $b_{m} b_{m-1} \ldots b_{1}$ where $a_{m} a_{m-1} \ldots a_{1} \geq b_{m} b_{m-1} \ldots b_{1}$ Wanted: $c_{m} c_{m-1} \ldots c_{1}$ which is equal to $a_{m} a_{m-1} \ldots a_{1}-b_{m} b_{m-1} \ldots b_{1}$ Step 1 Set the value of borrow to 0 Step 2 Set the value of $i$ to 1 Step 3 While the $i \leq(m)$ perform Steps 4 through 7 Step 4 Set value of $a_{i}$ to $a_{i}-$borrow Step 5 If $a_{i} \geq b_{i}$ then $c_{i}=a_{i}-b_{i}$ and set borrow $=0$ Step 6 Otherwise, $c_{i}=10-\left(b_{i}-a_{i}\right)$ and set borrow $=1$ Step 7 Add 1 to $i$ Step 8 Print the answer $c_{m} c_{m-1} \ldots c_{1}$ Step 9 Stop