You are on page 1of 8

NLSI Lui Kwok Pat Fong College

Information and Communication Technology (ICT) Ch.23 Algorithm Design (II)

Assignment

1. Which of the following shows the pseudocode of an assignment statement?

A. Input X
B. X ß A + 10
C. Output A
D. IF X < 10

2. Which of the following is not a condition control structure?

A. FOR-loop
B. WHILE-loop
C. Sequence control structure
D. IF statement

3. Which of the following is/are posttest loop?


(1) FOR-loop
(2) WHILE-loop
(3) DO…WHILE-loop
(4) REPEAT…UNTIL-loop

A. (1) and (3) only


B. (2) and (4) only
C. (3) and (4) only
D. (1), (3) and (4) only

4. Consider the following flowchart.

Loop-body

Ye
Condition
s

No

Which of the following iteration structures is shown above?

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

Which of the following iteration structures is shown above?

A. FOR-loop
B. WHILE-loop
C. DO…WHILE-loop
D. REPEAT…UNTIL-loop

6. Which of the following iteration structures initializes a variable at the


beginning?

A. FOR-loop
B. WHILE-loop
C. DO…WHILE-loop
D. REPEAT…UNTIL-loop

7. Which of the following statements is not the advantage of modular approach


in programming?

A. If some standard procedures are frequently used in a program, writing them


in separate modules can saves a lot of time from writing them again and
again.
B. Modularization allows a team of programmers to work on a single, large
program.
C. Modular approach allows the program runs faster.
D. Modularization makes a large project easier to be monitored and controlled.

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

9. Consider the following three algorithms.

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

Which of the above algorithms will return the same answer?

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

Which of the following will be the output of the algorithm?

A. 0
B. 1
C. 10
D. None of the above

11. Consider the following algorithm.


i ß 100
REPEAT
i ß i / 2
UNTIL i < 50
Output i

Which of the following will be the output of the algorithm?

A. 25
B. 50
C. 100
D. None of the above

12. Consider the following algorithm.


i ß 1
j ß 10
WHILE (i+j) <= 12
BEGIN
i ß i + 2
j ß j - 1
END
Output i

Which of the following will be the output of the algorithm?

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

Which of the following is the output of the algorithm?

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

What is the output of the algorithm?

A. The maximum of the array elements


B. The minimum of the array elements
C. The sum of the array elements
D. The average of the array elements

15. Consider the following algorithm.


k ß 0
FOR i ß 1 TO 20
FOR j ß 1 TO 30
k ß k + 1
NEXT
NEXT
Output k

What is the output of the algorithm?

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

How many variables have been used in the above pseudocode?

A. 4
B. 5
C. 9
D. The number of variables can only be determined when the program is run.

17. 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

Which line can be deleted without affecting the result?

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

Line 10 to Line 40 is used for _______________.

A. looping
B. testing data
C. initializing variables
D. inputting data

19. 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

How many assignment statements are used in the above pseudocode?

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?

A. This makes it easier for the programmer to add new statements


between
lines.
B. The interval of the line number can be 5.
C. If the line number is deleted, syntax errors will appear.
D. The line numbers ‘10’, ‘20’ and ‘30’ can be changed to ‘1’, ‘4’ and ‘9’
respectively.

You might also like