You are on page 1of 30

Chapter 5 Selection and Iteration Question Bank

Chapter 5 Selection and Iteration


Multiple Choice Questions

(U03C05L01Q001)
Suppose X = 1 and Y = 0. What is the value of X after execution of the following statements?
if X < Y
then X := X + 1
else X := X * 10
A. 1
B. 2
C. 10
D. 20
Answer
C

(U03C05L01Q002)
Suppose X = 5 and Y = 10. What are the values of variables X and Y after execution of the
following statements?
if X > Y
then X := Y
else Y := X
A. X = 5, Y = 5
B. X = 5, Y = 10
C. X = 10, Y = 10
D. X = 10, Y = 5
Answer
A

Computer & Information Technology for HKCEE 1 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q003)
What is the output of the following program segment if x = 6?
case x of
0: write(‘R’);
1, 3: write(‘S’);
4..9: write(‘T’)
end;
A. R
B. S
C. T
D. No output
Answer
C

(U03C05L01Q004)
What is the output of the following program segment if x = 2?
case x of
0: write(‘R’);
1, 3: write(‘S’);
4..9: write(‘T’)
end;
A. R
B. S
C. T
D. No output
Answer
D

Computer & Information Technology for HKCEE 2 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q005)
Suppose X = 1 and Y = 2. What is the output of the following program segment?
if X < Y
then write(‘R’)
else write(‘S’);
write(‘T’)
A. R
B. S
C. RT
D. ST
Answer
C

(U03C05L01Q006)
What is the output of the following program segment if x = 5?
......
if x >= 5
then write(‘A’)
else write(‘B’);
if x < 5
then write(‘C’)
else write(‘D’);
......
A. AC
B. AD
C. BC
D. BD
Answer
B

Computer & Information Technology for HKCEE 3 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q007)
What is the output of the following program segment if x = 50?
......
if x > 10
then if x < 100
then if x > 70
then writeln(‘A’)
else writeln(‘B’)
else writeln(‘C’)
else writeln(‘D’);
......
A. A
B. B
C. C
D. D
Answer
B

(U03C05L01Q008)
What is the value of x after execution of the following program segment?
......
x := 4;
if x < 5 then x := x + 1;
if x >= 5 then x := x + 1;
if x > 5 then x := x + 1;
......
A. 4
B. 5
C. 6
D. 7
Answer
D

Computer & Information Technology for HKCEE 4 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q009)
What is the output of the following program segment if score = 75?
......
if score > 75 then Grade := ‘A’ else Grade := ‘B’;
if score > 50 then Grade := ‘C’;
if score > 25 then Grade := ‘D’;
......
A. A
B. B
C. C
D. D
Answer
D

(U03C05L01Q010)
What is the function of the following program segment?
if X mod Y = 0
then write(‘YES’)
else write(‘NO’);
A. check if X is a factor of Y
B. check if Y is a factor of X
C. check if X is greater than Y
D. check if Y is greater than X
Answer
B

(U03C05L01Q011)
Which kind of iteration statement is suitable for executing a statement as long as a condition is
TRUE?
A. for-to-do statement
B. for-downto-do statement
C. while-do statement
D. repeat-until statement
Answer
C

Computer & Information Technology for HKCEE 5 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q012)
Which kind of iteration statement is suitable for executing a statement unless a condition is TRUE?
A. for-to-do statement
B. for-downto-do statement
C. while-do statement
D. repeat-until statement
Answer
D

(U03C05L01Q013)
What is the output of the following program segment?
X := 1;
for M = 1 to 10 do
X := X + M;
writeln(X);
A. 1
B. 10
C. 55
D. 56
Answer
D

(U03C05L01Q014)
Refer to the for-to-do statement below.
for I := -9 to 10 do
writeln(I);
How many times will the statement writeln(I); be executed?
A. 1
B. 10
C. 19
D. 20
Answer
D

Computer & Information Technology for HKCEE 6 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q015)
Refer to the for statement below.
for ________________________ do
writeln('*');
Which of the following cannot produce exactly 10 lines of output if it is the missing part of the for
statement?
A. I := 1 downto 10
B. I := 99 to 108
C. I := -5 to 4
D. I := 'a' to 'j'
Answer
A

(U03C05L01Q016)
Refer to the program segment below.
N := 99
while N <> 0 do
writeln(N);
N := N – 2;
How many times will the statement N := N – 2; be executed?
A. 0
B. 49
C. 50
D. 99
Answer
A

Computer & Information Technology for HKCEE 7 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q017)
Refer to the program segment below.
N := 99
while N <> 0 do
N := N – 2;
writeln(N);
How many times will the statement N := N – 2; be executed?
A 0
B 49
C 50
D Infinite number of times
Answer
D

(U03C05L01Q018)
Refer to the repeat-until statement below.
repeat
readln(X);
if X >= 100
then X := X – 100
else X := X + 100
until (0 < X) and (X < 100);
Which of the following input will stop execution of the repeat-until statement?
A 0
B 50
C 100
D 150
Answer
D

Computer & Information Technology for HKCEE 8 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L01Q019)
Refer to the program segment below.
for M := 0 to 10 do
for N := 5 downto 1 do
writeln('*');
How many lines of output are printed?
A 15
B 50
C 55
D. 60
Answer
C

Computer & Information Technology for HKCEE 9 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

Conventional Questions

(U03C05L02Q001)
Consider the following program.
program FindOutput;
var x, y, z : integer;
begin
readln(x, y, z);
if x > y
then if y > z
then write(‘y’)
else if x > z
then write(‘z’)
else write(‘x’)
else if x > z
then write(‘x’)
else if y > z
then write(‘z’)
else write(‘y’)
end.
What is the output if x, y and z have the following values?
x y z output
(a) 1 3 5
(b) 3 5 1
(c) 5 1 3
(d) 1 1 3
(e) 1 3 3
(f) 1 3 1

(6 marks)
Answers
(a) y
(b) x
(c) z
(d) y
(e) y
(f) y

Computer & Information Technology for HKCEE 10 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q002)
Write a program CheckSign which receives a number from users. Then the program checks
whether the number is positive, zero or negative and displays the result on screen.

Sample output 1
Enter a number: -3.4
Negative

Sample output 2
Enter a number: 0
Zero

Sample output 3
Enter a number: 59.5
Positive
(6 marks)
Answers
program CheckSign;
var X : real;
begin
write(‘Enter a number: ’);
readln(X);
if X > 0
then writeln(‘Positive’)
else if X = 0
then writeln(‘Zero’)
else writeln(‘Negative’)
end.

Computer & Information Technology for HKCEE 11 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q003)
Write a program Greeting which receives a time from users and then displays a greeting
according to the time. Refer to the following table for the greeting.
Time Greeting
04:00-11:59 Good morning
12:00-17:59 Good afternoon
18:00-20:59 Good evening
21:00-3:59 Good night

Sample output 1
What is the time now (hh mm)? 11 30
Good morning!

Sample output 2
What is the time now (hh mm)? 18 20
Good evening! (6 marks)
Answers
program Greeting;
var h, m : integer;
begin
write(‘What is the time now (hh mm)? ’);
readln(h, m);
case h of
0..3 : writeln(‘Good night!’);
4..11 : writeln(‘Good morning!’);
12..17 : writeln(‘Good afternoon!’);
18..20 : writeln(‘Good evening!’);
21..23 : writeln(‘Good night!’)
end
end.

Computer & Information Technology for HKCEE 12 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q004)
Write a program LeapYear which receives a year from users. Then the program checks whether it
is a leap year and displays the result on screen.
(Hint: It is a leap year if the year is divisible by 400, or the year is divisible by 4 but not divisible by
100.)

Sample output 1
Enter a year: 1900
It is not a leap year.

Sample output 2
Enter a year: 2000
It is a leap year. (7 marks)
Answers
program LeapYear;
var Year : integer;
begin
write(‘Enter a year: ’);
readln(Year);
if Year mod 400 = 0
then writeln(‘It is a leap year.’)
else if (Year mod 4 = 0) and (Year mod 100 <> 0)
then writeln(‘It is a leap year.’)
else writeln(‘It is not a leap year.’)
end.

Computer & Information Technology for HKCEE 13 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q005)
Write a program TimeConvert which receives a time in digital format and then displays the time
in words.
Sample output 1
Enter a time (hh mm): 3 15
A quarter past 3 o’clock

Sample output 2
Enter a time (hh mm): 11 40
20 minutes to 12 o’clock

Sample output 3
Enter a time (hh mm): 21 45
A quarter to 10 o’clock (12 marks)
Answers
program TimeConvert;
var h, m : integer;
begin
write(‘Enter a time (hh mm): ’);
readln(h, m);
if m <= 30
then begin
if m = 15
then write(‘A quarter past ’)
else if m = 30
then write(‘Half past ’)
else write(m,‘minutes past ’);
if h mod 12 <> 0
then writeln(h mod 12 , ‘ o’’clock’)
else writeln(‘12 o’’clock’)
end
else begin
if m = 45
then write(‘A quarter to ’)
else write(60 - m, ‘ minutes to ’);
writeln(h mod 12 + 1, ‘ o’’clock’)
end
end.

Computer & Information Technology for HKCEE 14 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q006)
Write a program CommonFactor which receives 3 integers from users. Then the program checks
whether the first integer is the common factor of the last two integers or not.

Sample output 1:
Enter 3 integers: 8 24 32
8 is a common factor of 24 and 32

Sample output 2:
Enter 3 integers: 7 35 18
7 is NOT a common factor of 35 and 18 (7 marks)
Answers
program CommonFactor;
var F, X, Y : integer;
begin
write(‘Enter 3 integers: ’);
readln(F, X, Y);
if (X mod F = 0) and (Y mod F = 0)
then writeln(F, ‘ is a common factor of ’, X, ‘ and ’,
Y)
else writeln(F, ‘ is NOT a common factor of ’, X, ‘ and
’, Y)
end.

Computer & Information Technology for HKCEE 15 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q007)
A program Calculator is written to simulate the working of a calculator. The program receives
two integers and one operator and then displays the result corrected to 2 decimal places.

Sample output 1:
Enter the first integer: 5
Enter the second integer: 12
Enter the operator (+ - * /): +
5 + 12 = 17.00

Sample output 2:
Enter the first integer: 62
Enter the second integer: 5
Enter the operator (+ - * /): /
62 / 5 = 12.40

(a) Complete the program Calculator below by using if-then statements.


program Calculator;
var M, N : integer;
Op: char;
begin
write(‘Enter the first integer: ’);
readln(M);
write(‘Enter the second integer: ’);
readln(N);
write(‘Enter the operator (+ - * /): ’);
readln(Op);
if Op = ‘+’
then writeln(M, ‘+’, N, ‘=’, M + N:0:2);
if Op = ‘-’
then writeln(__________________________);
if __________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
_____________________________________________
end.

Computer & Information Technology for HKCEE 16 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(b) Rewrite the if-then statement as nested-if statement.


(c) Rewrite the program body in part (a) by using a case statement instead of the
if-then statements. (10 marks)
Answers
(a)
program Calculator;
var M, N : integer;
Op: char;
begin
write(‘Enter the first integer: ’);
readln(M);
write(‘Enter the second integer: ’);
readln(N);
write(‘Enter the operator (+ - * /): ’);
readln(Op);
if Op = ‘+’
then writeln(M, ‘ + ’, N, ‘ = ’, M + N:0:2);
if Op = ‘-’
then writeln(M, ‘ - ’, N, ‘ = ’, M - N:0:2);
if Op = ‘*’
then writeln(M, ‘ * ’, N, ‘ = ’, M * N:0:2);
if Op = ‘/’
then writeln(M, ‘ / ’, N, ‘ = ’, M / N:0:2)
end.

(b)
if Op = ‘+’
then writeln(M, ‘ + ’, N, ‘ = ’, M + N:0:2)
else if Op = ‘-’
then writeln(M, ‘ - ’, N, ‘ = ’, M - N:0:2)
else if Op = ‘*’
then writeln(M, ‘ * ’, N, ‘ = ’, M * N:0:2)
else if OP = ‘/’
then writeln(M, ‘ / ’, N, ‘ = ’, M / N:0:2);

Computer & Information Technology for HKCEE 17 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(c)
begin
write(‘Enter the first integer: ’);
readln(M);
write(‘Enter the second integer: ’);
readln(N);
write(‘Enter the operator (+ - * /): ’);
readln(Op);
case Op of
‘+’ : writeln(M, ‘ + ’, N, ‘ = ’, M + N:0:2);
‘-’ : writeln(M, ‘ - ’, N, ‘ = ’, M - N:0:2);
‘*’ : writeln(M, ‘ * ’, N, ‘ = ’, M * N:0:2);
‘/’ : writeln(M, ‘ / ’, N, ‘ = ’, M / N:0:2)
end;

Computer & Information Technology for HKCEE 18 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q008)
Write a program ValidDate which receives the month and day from users and then checks
whether the date is valid or invalid. (Assume that it is not a leap year.)

Sample Output 1
Enter month: 12
Enter day: 31
VALID date!

Sample Output 2
Enter month: 9
Enter day: 31
INVALID date! (7 marks)
Answers
Program CheckDate;
var
dd, mm, LastDay : integer;
begin
write(‘Enter month: ’);
readln(mm);
write(‘Enter day: ’);
readln(dd);
case mm of
1, 3, 5, 7, 8, 10, 12 : LastDay := 31;
2 : LastDay := 29;
4, 6, 9, 10 : LastDay := 30
end;
if dd > LastDay
then writeln(‘INVALID date!’)
else writeln(‘VALID date!’)
end.

Computer & Information Technology for HKCEE 19 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q009)
Write a program ConvertDate which receives the year, month and day from users and then
displays the date in English format.

Sample Output 1
Enter year: 2003
Enter month: 12
Enter day: 21
The 21st of December 2003

Sample Output 2
Enter year: 2003
Enter month: 7
Enter day: 11
The 11th of July 2003 (12 marks)

Computer & Information Technology for HKCEE 20 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

Answers
Program ConvertDate;
var
dd, mm, yyyy : integer;
begin
write(‘Enter year: ’);
readln(yyyy);
write(‘Enter month: ’);
readln(mm);
write(‘Enter day: ’);
readln(dd);
if dd mod 10 <= 3
then if (dd = 11) or (dd = 12) or (dd = 13)
then write(‘The ’, dd, ‘th of’)
else case dd mod 10 of
1: write(‘The ’, dd, ‘st of ’);
2: write(‘The ’, dd, ‘nd of ’);
3: write(‘The ’, dd, ‘rd of ’)
end
else write(‘The ’, dd, ‘th of ’);
case mm of
1: write(‘January ’);
2: write(‘February ’);
3: write(‘March ’);
4: write(‘April ’);
5: write(‘May ’);
6: write(‘June ’);
7: write(‘July ’);
8: write(‘August ’);
9: write(‘September ’);
10: write(‘October ’);
11: write(‘November ’);
12: write(‘December ’)
end;
writeln(yyyy)
end.

Computer & Information Technology for HKCEE 21 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q010)
What is the output of the following program segment?
for I := 1 to 10 do
if I mod 2 = 0
then write(I); (2 marks)
Answers
246810

(U03C05L02Q011)
Refer to the program segment below.
for X := -4 to 100 do
writeln(‘*’);
writeln(X);
(a) What is the initial value of X when the for-to-do statement is executed?
(b) What is the value of X after the for-to-do statement is executed?
(c) Which statement(s) will be executed repeatedly?
(d) How many times will the statement in (c) be executed?
(e) How many times will the statement writeln(X); be executed?
(5 marks)
Answers
(a) –4
(b) 100
(c) writeln(‘*’);
(d) 105
(e) 1

Computer & Information Technology for HKCEE 22 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q012)
Refer to the program segment below.
for Y := 99 downto 19 do
begin
writeln(Y);
writeln(‘*’)
end;
writeln(‘Bye!’);
(a) What is the initial value of Y when the for-downto-do statement is executed?
(b) What is the value of Y after the for-downto-do statement is executed?
(c) Which statement(s) will be executed repeatedly?
(d) How many times will the statement writeln(‘*’) be executed?
(e) How many times will the statement writeln(‘Bye!’); be executed?
(5 marks)
Answers
(a) 99
(b) 19
(c) writeln(Y);
writeln(‘*’)
(d) 81
(e) 1

Computer & Information Technology for HKCEE 23 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q013)
Refer to the program segment below.
readln(Mark)
while Mark > 100 do
begin
write(‘Exceeds 100! Enter again: ’);
readln(Mark)
end;
writeln(‘Valid!’);
(a) What is the condition of this while-do statement?
(b) Which statement(s) will be executed if the condition is TRUE?
(c) Which statement(s) will be executed if the condition is FALSE?
(d) What should be entered initially for Mark so that the loop statement within the while-do
statement will be executed?
(e) What should be entered initially for Mark so that the loop statement within the while-do
statement will be skipped?
(5 marks)
Answers
(a) Mark > 100
(b) write(‘Exceed 100! Enter again: ’);
readln(Mark)
(c) writeln(‘Valid!’);
(d) A number which is greater than 100
(e) A number which is less than or equal to 100

Computer & Information Technology for HKCEE 24 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q014)
Refer to the program segment below.
repeat
write(‘Enter a number: ’);
readln(X)
until X > 1000;
writeln(‘OK’);
(a) What is the condition of the repeat-until statement?
(b) Which statement(s) will be executed if the condition is TRUE?
(c) Which statement(s) will be executed if the condition is FALSE?
(d) What should be entered initially for X so that the loop statement within the repeat-until
statement will be executed again?
(e) What should be entered initially for X so that the loop statement within the repeat-until
statement will be executed only once?
(5 marks)
Answers
(a) X > 1000
(b) writeln(‘OK’);
(c) write(‘Enter a number: ’);
readln(X)
(d) A number which is less than or equal to 1000
(e) A number which is greater than 1000

Computer & Information Technology for HKCEE 25 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q015)
Refer to the program segment below.
writeln(‘!’);
for M := 1 to 10 do
begin
for N := 10 downto 5 do
witeln(‘*’);
writeln(‘@’)
end;
Write down the number of times each of the following statements is executed.
(a) writeln(‘!’);
(b) writeln(‘*’);
(c) writeln(‘@’)
(3 marks)
Answers
(a) 1
(b) 60
(c) 10

Computer & Information Technology for HKCEE 26 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q016)
Rewrite the program segment below using a repeat-until statement.
OK := FALSE;
while not OK do
begin
readln(Password);
if Password = ‘xyzabc123’
then OK := TRUE
end; (2 marks)
Answers
OK := FALSE;
repeat
readln(Password);
if Password = ‘xyzabc123’
then OK := TRUE
until OK

(U03C05L02Q017)
A programmer wants to write a program segment to receive a number from users. The number must
be within the range from 1 to 999. Otherwise, users have to input again.
(a) Use a repeat-until statement to write the program segment for the programmer.
(b) Use a while-do statement to write the program segment for the programmer.
You may use an integer variable N in your program segment. (6 marks)
Answers
(a) repeat
readln(N);
until (N >= 1) and (N <= 999);
(b) readln(N)
while (N < 1) or (N > 999) do
readln(N);

Computer & Information Technology for HKCEE 27 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(U03C05L02Q018)
(a) Refer to the for-to-do statement below.
for X := 1 to ___ do
write(‘*’);
Complete the for-to-do statement to print the following output.
(i) Sample Output 1
***
(ii) Sample Output 2
**********
(b) An integer variable Width is declared. Use the for-to-do statement in part (a) with this
variable to write a program segment which lets users input a number as the width of the line
(i.e. number of “*”) displayed.

Sample Output 1
Enter the WIDTH of the line: 3
***

Sample Output 2
Enter the WIDTH of the line: 10
**********
(c) Refer to the for-to-do statement below.
for Y := 1 to ___ do
writeln(‘***************’);
Complete the for-to-do statement to print the following output.
(i) Sample Output 1
***************
***************
***************
(ii) Sample Output 2
***************
***************
***************
***************
***************

Computer & Information Technology for HKCEE 28 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

(d) An integer variable Height is declared. Use the for-to-do statement in part (c) and the
variable to write a program segment which lets users input a number as the number of lines
displayed.
Sample Output 1
Enter the HEIGHT of the lines: 3
***************
***************
***************
Sample Output 2
Enter the HEIGHT of the lines: 5
***************
***************
***************
***************
***************
(e) Write a program Rectangle which receives the width and the height from keyboard and
then display a rectangle constructed by “*” with size same as the inputted width and height.
Sample Output 1
Enter the WIDTH of the rectangle: 15
Enter the HEIGHT of the rectangle: 5
***************
***************
***************
***************
***************
Sample Output 2
Enter the WIDTH of the rectangle: 25
Enter the HEIGHT of the rectangle: 3
*************************
*************************
************************* (15 marks)

Computer & Information Technology for HKCEE 29 © Pearson Education Asia Limited 2004
(Module A2)
Chapter 5 Selection and Iteration Question Bank

Answers
(a) (i) for X := 1 to 3 do
write(‘*’);
(ii) for X := 1 to 10 do
write(‘*’);
(b) write(‘Enter the WIDTH of the line: ’);
readln(Width);
for X := 1 to Width do
write(‘*’);
(c) (i) for Y := 1 to 3 do
writeln(‘***************’);
(ii) for y := 1 to 5 do
writeln(‘***************’);
(d) write(‘Enter the HEIGHT of the lines: ’);
readln(Height);
for Y := 1 to Height do
writeln(‘***************’);
(e) program Rectangle;
var
X, Y, Width, Height : integer;
begin
write(‘Enter the WIDTH of the rectangle: ’);
readln(Width);
write(‘Enter the HEIGHT of the rectangle: ’);
readln(Height);
for Y := 1 to Height do
begin
for X := 1 to Width do
write(‘*’);
writeln
end
end.

Computer & Information Technology for HKCEE 30 © Pearson Education Asia Limited 2004
(Module A2)

You might also like