Algorithm Design (I)
7
Study the following flowchart and answer questions
1 to 3. The flowchart shows the process of evaluating
the length of the hypotenuse of a right-angled
triangle, given that the lengths of the other two sides
are X and Y.
Input X...
More
Algorithm Design (I)
7
Study the following flowchart and answer questions
1 to 3. The flowchart shows the process of evaluating
the length of the hypotenuse of a right-angled
triangle, given that the lengths of the other two sides
are X and Y.
Input X
Output M
Box A
Box B
End
Start
1. What should be the instruction in Box A?
A. B ← Y
B. Y ← B
C. Input X
D. Input Y
2. What should be the instruction in Box B?
A. B ← Sqrt(X*X + Y*Y)
B. M ← Sqrt(X*X + Y*Y)
C. X ← Sqrt(X*X + Y*Y)
D. Y ← Sqrt(X*X + Y*Y)
D
D
B
B
3. Which of the following input pairs will cause a
run-time error when the flowchart is executed?
(1) 5, 0
(2) X, Y
(3) –2, 2
A. (1) only
B. (2) only
C. (1) and (3) only
D. (2) and (3) only
4. Convert the following flowchart to pseudocode.
X ← X + 1
X < 0 X ← X * (–1)
Yes
No
A. IF (X < 0) THEN X ← X * (-1)
X ← X + 1
B. IF (X < 0) THEN X ← X * (-1)
ELSE X ← X + 1
C. IF (X > 0) THEN X ← X + 1
ELSE X ← -1 * X
D. IF (X > 0) THEN X ← (-X) + 1
X ← X + 1
B
B
A
A
Multiple Choice Questions
Less