Machine Problems: Reads


1. n =
2. m = n + 1
3. print m
4. stop

What will this machine do if the number it reads is 17?

What will this machine do if the number it reads is 23?

What will this machine do if the number it reads is -5?


1. n = READ
2. m = READ
3. s = n + m
4. print s
5. stop

What will this machine do if the numbers it reads are 42 and 37?

What will this machine do if the numbers it reads are 26 and 36?

What will this machine do if the numbers it reads are 3 and -5?

Be the Machinemaster

Write machine instructions to read two numbers, subtract the second number from the first, and print the result

Write instructions to read three numbers, add them, and print the result.

Write instructions to read two numbers, multiply them, read a third number, add it to the product of the first two numbers, then print the result.

More Being the Machine

1. p = READ
2. q = READ
3. print p
4. p = p + 1
5. Stop if p = q
6. Go to #3

What will this machine do if the numbers it reads are 1 and 10?

What will this machine do if the numbers it reads are 7 and 12?

What will this machine do if the numbers it reads are 7 and 2?


1. n1 = READ
2. s = n1
3. n2 = READ
4. go to #8 if s < n2
5. s = n2
6. print s
7. Stop

What will this machine do if the numbers it reads are 0 and 8?

What will this machine do if the numbers it reads are 6 and 2?

What will this machine do if the numbers it reads are 3 and 62?

What will this machine do if the numbers it reads are 24 and 25?


1. i = 0
2. n = 0
3. w = READ
4. n = n + w
5. i = i + 1
6. Go to #3 if i < 5
7. print n
8. Stop.

What will this machine do if the numbers it reads are 7, 12, 2?

What will this machine do if the numbers it reads are 14, 23, 92, 6, 1?

What do these instructions accomplish?


1. n = 0
2. w = READ
3. Go to #7 if the read failed
4. n = n + w
5. Go to #3 if i < 5
6. print n.
7. Stop.

What will this machine do if the numbers it reads are 7, 12, 2?

What will this machine do if the numbers it reads are 14, 23, 92, 6, 1?

What do these instructions accomplish?

More Machinemaster

Write instructions that will read numbers and subtract them from 100.

Write instructions that will read numbers and multiply them.

Difficult Machine Problem

1. m = 1000
2. w = READ
3. Go to #7 if the read failed
4. go to #7 if w > m
5. m = w
6. Go to #3
7. print m
8. Stop.

What will this machine do if the numbers it reads are 47, 23, 98, 1, 52

What will this machine do if the numbers it reads are 3, 90, 91, 92, 93, 94, 95?

What do these instructions accomplish?