Programming – Pascal: Essential skills 8
Other commands
Random()
To generate different random numbers when the same program
is run, use the command randomize.
Random(100) generates
a number with a possible range of 0 – 99.
var a :
integer; begin randomize; (*
when the same program is run again, a different set of random number is
generated *) a := Random(100) + 1 (*
possible values of a = 1-100 *) end; |
Trunc()
The function trunc() changes a real number into an integer
by simply removing the decimal part.
e.g. trunc(2.99) becomes 2
Multiple select: case … of
Instead of using multiple if… statements, we can better organize
the program by using case … of.
var a :
integer; being case
a of 1..3
: writeln (‘less than 4’); 4..6
: writeln (‘between 4 and 6’); 7..9 : writeln
(‘between 7 and 9’) else Writeln (‘out
of range’) end end; |
Relevant past paper:
DSE ICT Elect B(SP-2017):
2013 3di.
CE CIT Elect A(2005-2011): 2007 3ab. 2009 1ad, 4bi. 2010 3bcd.
No comments:
Post a Comment