Ch.23 Algorithm Design II - Assignment - Ans
Ch.23 Algorithm Design II - Assignment - Ans
Assignment
A. Input X
B. X ß A + 10
C. Output A
D. IF X < 10
A. FOR-loop
B. WHILE-loop
C. Sequence control structure
D. IF statement
Loop-body
Ye
Condition
s
No
A. FOR-loop
B. WHILE-loop
C. DO…WHILE-loop
D. REPEAT…UNTIL-loop
1
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
5. Consider the following flowchart.
Loop-body
No
Condition
Ye
s
A. FOR-loop
B. WHILE-loop
C. DO…WHILE-loop
D. REPEAT…UNTIL-loop
A. FOR-loop
B. WHILE-loop
C. DO…WHILE-loop
D. REPEAT…UNTIL-loop
2
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
8. Consider the following algorithm.
Input X
Y ß 0
FOR i ß 1 TO X
Y ß Y + i
NEXT
Output Y
Which of the following will be the output of this algorithm if ‘4’ is inputted?
A. 4
B. 6
C. 10
D. 15
Algorithm 1:
sum ß 0
FOR i ß 2 TO 6
sum ß sum + i
NEXT
Output sum
Algorithm 2:
sum ß 0
i ß 2
REPEAT
sum ß sum + i
UNTIL i > 6
Output sum
Algorithm 3:
sum ß 0
i ß 2
WHILE i < 7
BEGIN
sum ß sum + i
END
Output sum
A. 1 and 2 only
B. 1 and 3 only
C. 2 and 3 only
D. 1, 2 and 3
3
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
10. Consider the following algorithm.
i ß 10
WHILE i > 1
BEGIN
IF i > 0 THEN
i ß i + 1
ELSE
i ß i - 5
ENDIF
END
Output i
A. 0
B. 1
C. 10
D. None of the above
A. 25
B. 50
C. 100
D. None of the above
A. 0
B. 1
C. 3
D. 5
4
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
13. Consider the following algorithm.
i ß 1
DO
BEGIN
i ß i * 2
END
WHILE i < 30
Output i
A. 1
B. 16
C. 30
D. 32
14. The following algorithm manipulates the array A which has 100 integers.
x ß 0
FOR i ß 1 TO 100
x ß A[i]
NEXT
Output x
A. 20
B. 30
C. 50
D. 600
5
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
16. Study the following pseudocode.
Line Content
10 W ß 5
20 X ß 10
30 Y ß 20
40 Z ß 30
50 X ß X + Y
60 W ß Y + Z
70 Z ß Z - W
80 V ß X + Z
90 Y ß Y - 1
A. 4
B. 5
C. 9
D. The number of variables can only be determined when the program is run.
A. Line 10
B. Line 20
C. Line 30
D. Line 40
6
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
18. Study the following pseudocode.
Line Content
10 W ß 5
20 X ß 10
30 Y ß 20
40 Z ß 30
50 X ß X + Y
60 W ß Y + Z
70 Z ß Z – W
80 V ß X + Z
90 Y ß Y – 1
A. looping
B. testing data
C. initializing variables
D. inputting data
A. 4
B. 5
C. 9
D. 90
7
NLSI Lui Kwok Pat Fong College
Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)
20. Study the following pseudocode.
Line Content
10 W ß 5
20 X ß 10
30 Y ß 20
40 Z ß 30
50 X ß X + Y
60 W ß Y + Z
70 Z ß Z - W
80 V ß X + Z
90 Y ß Y - 1
In the above pseudocode, the interval of the line number is 10. (i.e. The first
line number is 10, the second one is 20 and so on.) Which of the following
statements is not correct?