## Invitation to Computer Science 8th Edition

We're given the values $\begin{array}{rl}{m} & {=3} \\ {a_{2}=1} & {a_{1}=4} & {a_{0}=9} \\ {b_{2}=0} & {b_{1}=2} & {b_{0}=9}\end{array}$ We will now perform the same procedure as was described below Figure 1.2 for adding 47 and $25 .$ ______________________________________________________________ So that I don't have so many columns that this becomes unreadable, I won't keep track of the $c_{i}$\or carry at each step, but instead will simply bold when they are (re) set to values. On your own paper feel free to make extra columns for each variable of interest. Step $1 : \quad$ carry $=0$ Step $2 : \quad i=0$ Step $3 :$ We now repeat Steps 4 through 6 while $i$ is less than or equal to 2 First repetition of the loop (i has the value 0$)$ Step $4 : \quad \operatorname{Add}\left(a_{0}+b_{0}+\text { carry }\right)$ , which is $9+9+0,$ so $c_{0}=18$ Step $5 : \quad$ Because $c_{0} \geq 10,$ we reset $c_{0}$ to 8 and reset carry to 1 Step $6 : \quad$ Reset $i$ to $(0+1)=1 .$ Because $i$ is less than or equal to $2,$ go back to Step 4 Second repetition of the loop (i has the value 1) Step $4 : \quad \operatorname{Add}\left(a_{1}+b_{1}+\text { carry }\right),$ which is $4+2+1,$ so $\mathbf{c}_{1}=7$ Step $5 : \quad$ Because $c_{1}<10,$ we reset carry to 0 Step $6 :$ Reset $i$ to $(1+1)=2 .$ Because $i$ is less than or equal to $2,$ go back to Step 4 First repetition of the loop (i has the value 2) Step $4 :$ Add $\left(a_{2}+b_{2}+\text { carry }\right)$ , which is $1+0+0,$ so $\mathbf{c}_{2}=1$ Step $5 : \quad$ Because $c_{2}<10,$ we reset carry to 0 Step $6 : \quad$ Reset $i$ to $(2+1)=3 .$ Because $i$ is greater than $2,$ we do not repeat the loop but instead go to Step 7 $\begin{array}{ll}{\text { Step } 7 :} & {\text { Set } \mathbf{c}_{3}=\mathbf{0}} \\ {\text { Step } 8 :} & {\text { Print out the answer } c_{3} c_{2} c_{1} c_{0}=0178} \\ {\text { Step } 9 :} & {\text { Stop }}\end{array}$ __________________________________________________________________ Hence, using our adding algorithm we find that $149+29=178,$ as expected.
We're given the values $\begin{array}{rl}{m} & {=3} \\ {a_{2}=1} & {a_{1}=4} & {a_{0}=9} \\ {b_{2}=0} & {b_{1}=2} & {b_{0}=9}\end{array}$ We will now perform the same procedure as was described below Figure 1.2 for adding 47 and $25 .$ ______________________________________________________________ So that I don't have so many columns that this becomes unreadable, I won't keep track of the $c_{i}$ s or carry at each step, but instead will simply bold when they are (re) set to values. On your own paper feel free to make extra columns for each variable of interest. Step $1 : \quad$ carry $=0$ Step $2 : \quad i=0$ Step $3 :$ We now repeat Steps 4 through 6 while $i$ is less than or equal to 2 First repetition of the loop (i has the value 0$)$ Step $4 : \quad \operatorname{Add}\left(a_{0}+b_{0}+\text { carry }\right)$ , which is $9+9+0,$ so $c_{0}=18$ Step $5 : \quad$ Because $c_{0} \geq 10,$ we reset $c_{0}$ to 8 and reset carry to 1 Step $6 : \quad$ Reset $i$ to $(0+1)=1 .$ Because $i$ is less than or equal to $2,$ go back to Step 4 Second repetition of the loop (i has the value 1) Step $4 : \quad \operatorname{Add}\left(a_{1}+b_{1}+\text { carry }\right),$ which is $4+2+1,$ so $\mathbf{c}_{1}=7$ Step $5 : \quad$ Because $c_{1}<10,$ we reset carry to 0 Step $6 :$ Reset $i$ to $(1+1)=2 .$ Because $i$ is less than or equal to $2,$ go back to Step 4 First repetition of the loop (i has the value 2) Step $4 :$ Add $\left(a_{2}+b_{2}+\text { carry }\right)$ , which is $1+0+0,$ so $\mathbf{c}_{2}=1$ Step $5 : \quad$ Because $c_{2}<10,$ we reset carry to 0 Step $6 : \quad$ Reset $i$ to $(2+1)=3 .$ Because $i$ is greater than $2,$ we do not repeat the loop but instead go to Step 7 $\begin{array}{ll}{\text { Step } 7 :} & {\text { Set } \mathbf{c}_{3}=\mathbf{0}} \\ {\text { Step } 8 :} & {\text { Print out the answer } c_{3} c_{2} c_{1} c_{0}=0178} \\ {\text { Step } 9 :} & {\text { Stop }}\end{array}$ __________________________________________________________________ Hence, using our adding algorithm we find that $149+29=178,$ as expected.