Page 87 - Introduction to Programming with Java: A Problem Solving Approach
P. 87

                5. [after §2.11] Trace the following algorithm. The book presents two ways to do tracing—a short form and a long form. To give you a head start, the setup for the short form and also the long form are given below. For your answer, pick one setup and use it. Skip the other setup.
5
6
7
8
2
3
4
1
setyto0
input x
while x is not equal to y
set y to value of x input x
set x to x 􏰀 y print “x = ” x print“y =”y
Short-form setup:
input x y 2
3
4
output
Exercises 53
    0
Long-form setup:
input 2
3
4
0.
Apago PDF Enhancer
  line#
 x
 y
 output
 6. [after §2.11] Trace the following algorithm. The book presents two ways to do tracing—a short form and a long form. To give you a head start, the setup for the short form and also the long form are given below. For your answer, pick one setup and use it. Skip the other setup.
1
setnumto2
set count to 1
while count is less than 5
setcounttocount * num if count / 2 is less than 2
print “Hello” else
while count is less than 7 set count to count 􏰀 1
2
3
4
5
6
7
8
9
print “The count is” count “.” Short-form setup:
num count output Long-form setup:
10
    line#
 num
 count
 output
 












































   85   86   87   88   89