5.
Step 1:
carry
= 0,
c
3
= ??,
c
2
= ??,
c
1
= ??, and
c
0
= ??
Step 2:
i = 0,
all others unchanged
Step 4:
c
0
= 18, all others unchanged
Step 5:
c
0
= 8 and
carry
= 1, all others unchanged
Step 6:
i
= 1,
carry
= 1,
c
3
= ??,
c
2
= ??,
c
1
= ??, and
c
0
= 8
Step 4:
c
1
= 7, all others unchanged
Step 5:
carry
= 0, all others unchanged
Step 6:
i
= 2,
carry
= 0,
c
3
= ??,
c
2
= ??,
c
1
= 7, and
c
0
= 8
Step 4:
c
1
= 1, all others unchanged
Step 5:
carry
= 0, all others unchanged
Step 6:
i
= 3,
carry
= 0,
c
3
= ??,
c
2
= 1,
c
1
= 7, and
c
0
= 8
Step 7:
c
3
= 0,
c
2
= 1,
c
1
= 7, and
c
0
= 8
Step 8:
Print out 0178.
6.
Replace Step 8 with the following steps:
Step 8:
Set the value of
i
to
m
Step 9:
Repeat step 10 until either
c
i
is not equal to 0 or
i
< 0
Step 10:
Subtract 1 from
i
, moving one digit to the right
Step 11:
If
i
>
0 then print
c
i
c
i-1
. . .
c
0
7
.
Assume that
a
has
n
digits a
n-1
, … , a
0
, and
b
has
m
digits, b
m-1
, … , b
0
, with
n
not necessarily
equal to
m
. Add an operation at the beginning of the algorithm that resets the two numbers to the
same number of digits by adding non-significant leading zeros to the shorter one.
We can then
reuse the algorithm of Figure 1.2.