Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 1 - Exercises - Page 39: 5

Answer

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.

Work Step by Step

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.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.