The following numbers are displayed by a program:
2468
The program code is shown below, but it is missing three values:
, , and .
i -
REPEAT TIMES
{
DISPLAY (i * 2)
i
-it
}
Given the displayed output, what must the missing values be?
Choose 1 answer:
= 2, = 2, = 1
A
B
= 2, = 4,
= 1, = 4, = 1
C
= 2, = 4, = 2
D
E
= 1, = 2, = 2
Given the code snippet:
Let's analyze each answer choice:
1.
Choice A: <COUNTER> = 2, <AMOUNT> = 2, <STEP> = 1
- Initial value of
"i" is 2.
- Repeat 2 times:
- DISPLAY (2 * 2) -> 4
- i <- 2 + 1 -> 3
- DISPLAY (3 * 2) -> 6
- Output: 4 6 (Incorrect)
2.
Choice B: <COUNTER> = 2, <AMOUNT> = 4, <STEP> = 1
- Initial value of
"i" is 2.
- Repeat 4 times:
- DISPLAY (2 * 2) -> 4
- i <- 2 + 1 -> 3
- DISPLAY (3 * 2) -> 6
- i <- 3 + 1 -> 4
- DISPLAY (4 * 2) -> 8
- i <- 4 + 1 -> 5
- DISPLAY (5 * 2) -> 10
- Output: 4 6 8 10 (Incorrect)
3.
Choice C: <COUNTER> = 1, <AMOUNT> = 4, <STEP> = 1
- Initial value of
"i" is 1.
- Repeat 4 times:
- DISPLAY (1 * 2) -> 2
- i <- 1 + 1 -> 2
- DISPLAY (2 * 2) -> 4
- i <- 2 + 1 -> 3
- DISPLAY (3 * 2) -> 6
- i <- 3 + 1 -> 4
- DISPLAY (4 * 2) -> 8
- Output: 2 4 6 8 (Correct)
4.
Choice D: <COUNTER> = 2, <AMOUNT> = 4, <STEP> = 2
- Initial value of
"i" is 2.
- Repeat 4 times:
- DISPLAY (2 * 2) -> 4
- i <- 2 + 2 -> 4
- DISPLAY (4 * 2) -> 8
- i <- 4 + 2 -> 6
- DISPLAY (6 * 2) -> 12
- i <- 6 + 2 -> 8
- DISPLAY (8 * 2) -> 16
- Output: 4 8 12 16 (Incorrect)
5.
Choice E: <COUNTER> = 1, <AMOUNT> = 2, <STEP> = 2
- Initial value of
"i" is 1.
- Repeat 2 times:
- DISPLAY (1 * 2) -> 2
- i <- 1 + 2 -> 3
- DISPLAY (3 * 2) -> 6
- Output: 2 6 (Incorrect)
Not the question you are looking for? Ask here!
Enter question by text
Enter question by image
Unlock Smarter Learning with AskSia Super!
Join Super, our all-in-one AI solution that can greatly improve your learning efficiency.