PeterRobinson44
New member
- Joined
- May 14, 2020
- Messages
- 12
The answer is 32. However, I am trying to determine how many times the count changes in the problem. Is it 5 because it goes from 4 to 3 to 2 to 1 to 0? Or 4 because it goes from 4 to 3 to 2 to 1? I am overthinking this question and would appreciate any help.
Given the pseudocode fragment:
x: = 2
count: = 4
while (count > 0)
x: = 2 * x
count: = count - 1
End-while
What is the final value for x?
x = 2
count = 4
4 > 0
x: 2 * 2 = 4
count = 3
x = 4
count = 3
3 > 0
x: 2 * 4 = 8
count = 2
x = 8
count = 2
2 > 0
x: 2 * 8 = 16
count = 1
x = 16
count = 1
1 > 0
x: 2 * 16 = 32
count = 0
Given the pseudocode fragment:
x: = 2
count: = 4
while (count > 0)
x: = 2 * x
count: = count - 1
End-while
What is the final value for x?
x = 2
count = 4
4 > 0
x: 2 * 2 = 4
count = 3
x = 4
count = 3
3 > 0
x: 2 * 4 = 8
count = 2
x = 8
count = 2
2 > 0
x: 2 * 8 = 16
count = 1
x = 16
count = 1
1 > 0
x: 2 * 16 = 32
count = 0