SELF TEST: ANSWERS

1. Write a Pascal statement to define an array called numbers, which is an integer array with elements ranging from 1 to 20


	type  numbers = ARRAY[1..20] of integer;

2. Write a Pascal statement to create an array called mynumbers, of type numbers, which was defined in 1. above

	var  mynumbers : numbers;

3. Write a Pascal statement which assigns the integer value 20 to element 4 of the array mynumbers, which was declared in 2. above

	mynumbers[4] := 20;

4. Write Pascal statements which define a packed array of characters (15 elements), called word, create a working variable of type word called myword, and then reads input from the keyboard into the array myword

	type  word = PACKED ARRAY[1..15] of char;
	var   myword : word;

	begin
		readln( myword );

5. Write Pascal statements which will sum the contents of an integer array called mynumbers, which has 20 elements numbered 1 to 20

	total := 0;
	for loop := 1 to 20 do
		total := total + mynumbers[loop];

6. Write a Pascal statement which will initialise a packed character array called message to the string 'Hello there!'. The array has thirteen elements

	message := 'Hello there! ';

7. Write a Pascal statement to display the ASCII value of the letter 'A'

	writeln( ord('A') );

8. Write a Pascal statement to display the character represented by the ASCII value 52

	writeln( chr(52) );

9. Write a Pascal statement to display the character which follows 'F'

	writeln( succ('F') );

10. Write a Pascal statement to display the character which comes before 'Z'

	writeln( pred('Z') );


Copyright B Brown/P Henry/CIT, 1988-1996. All rights reserved.