Question 1
1. Finding the Minimum Value in an Array
An incomplete algorithm has been written in pseudocode to find the smallest value stored in
an array. Values have been stored in the array starting at A[1]. A value of -1 in the array
indicates there are no more values stored. Complete the algorithm to determine and display
the smallest value.
2. Counting Odd Numbers in an Array
An incomplete algorithm has been written in pseudocode to count the number of odd
numbers stored in an array. The values are stored in the array starting at A[1]. A value of 0 in
the array indicates there are no more values stored. Complete the algorithm to count and
display the number of odd numbers.
3. Calculating the Product of Values in an Array
An incomplete algorithm has been written in pseudocode to calculate the product of all
nonzero values in an array. The array starts at A[1], and a value of -1 in the array indicates
the end of the data. Complete the algorithm to compute and display the product of all
values in the array.
4. Finding the Index of a Target Value in an Array
An incomplete algorithm has been written in pseudocode to search for a specific value in an
array. The values are stored in the array starting at A[1]. A value of 0 in the array indicates
there are no more values stored. The target value to be found is stored in the variable target.
Complete the algorithm to determine and display the index of the target value if it exists,
otherwise display "Not Found".
5. Finding the Mode of an Array (Most Frequent Value)
An incomplete algorithm has been written in pseudocode to find the mode (most frequently
occurring value) in an array. The values are stored in the array starting at A[1]. A value of -1
in the array indicates the end of the data. Complete the algorithm to determine and display
the mode of the array.
6. Rearranging an Array (Swapping First and Last Elements)
An incomplete algorithm has been written in pseudocode to swap the first and last elements
of an array. The values are stored in the array starting at A[1]. A value of -1 in the array
indicates there are no more values stored. Complete the algorithm to swap the first and last
elements and display the updated array.
Question 2
Write an algorithm in pseudocode, using a single loop, to print 50 names that have been
stored in an array.
Question 3
The pseudocode algorithm shown should allow numbers to be entered and should allow
50 numbers to be stored in an array.
Count ← 0
REPEAT
INPUT Values[Count]
Count ← Count + 1
UNTIL Count = 0
(a) Explain why the algorithm will never end.
(b) Re-write the original pseudocode so that it terminates correctly and also prevents
numbers below 100 from being stored in the array Values[ ]
(c)Describe how you could change your pseudocode in part (b) so that it prevents numbers
below 100 and above 200 from being stored in the array Values[ ]
Question 4
(a) An algorithm has been written in pseudocode to input the names and marks of 35
students.
The algorithm stores the names and marks in two arrays Name[ ] and Mark[ ]. The highest
mark awarded is found and the number of students with that mark is counted. Both of these
values are output.
01 HighestMark ← 100
02 HighestMarkStudents ← 0
03 FOR Count ← 1 TO 35
04 OUTPUT "Please enter student name"
05 INPUT Name[Count]
06 OUTPUT "Please enter student mark"
07 INPUT Mark[Counter]
08 IF Mark[Count] = HighestMark
09 THEN
10 HighestMarkStudents ← HighestMarkStudents – 1
11 ENDIF
12 IF Mark[Count] > HighestMark
13 THEN
14 Mark[Count] ← HighestMark
15 HighestMarkStudents ← 1
16 ENDIF
17 NEXT Count
18 OUTPUT "There are ", HighestMarkStudents," with the highest mark of ",
HighestMark
Give line numbers where the four errors are to be found in the pseudocode. Suggest a
correction for each error.
(b) Explain how you could extend the algorithm to also find the lowest mark awarded, count
the number of students with that mark, and output both these values.
Question 5
The following pseudocode algorithm uses nested IF statements.
Re-write the pseudocode algorithm using a CASE statement.
Question 6
a) REPEAT ... UNTIL and WHILE ... DO ... ENDWHILE are two different loop
structures you can use when writing pseudocode.
Explain, using examples, why you would choose to use each type of loop.
IF ... THEN ... ELSE ... ENDIF and CASE ... OF ... OTHERWISE ... ENDCASE
are two different conditional statements that you can use when writing pseudocode.
a) Explain, using examples, why you would choose to use each conditional statement.
Question 7
Read this section of program code that inputs 10 positive numbers and then outputs the
smallest number input.
1 Small = 1000
2 Counter = 0
3 REPEAT
4 INPUT Num
5 IF Num < Small THEN Small = Num
6 Counter = Counter + 1
7 UNTIL Counter = 10
8 PRINT Small
(i) Identify three changes you would need to make to find the largest number input instead
of the smallest number.
(ii) Rewrite the program code with your changes.
Question 8
(a) Describe the purpose of each statement in this algorithm.
FOR I 1 TO 300
INPUT Name[I]
NEXT I
(b) Identify, using pseudocode, another loop structure that the algorithm in part (a) could
have used.
(c) Write an algorithm, using pseudocode, to input a number between 0 and 100 inclusive.
The algorithm should prompt for the input and output an error message if the number is
outside this range.
Question 9
An algorithm has been written in pseudocode to input 100 numbers and print out the sum.
A REPEAT … UNTIL loop has been used.
Count ← 0
Sum ← 0
REPEAT
INPUT Number
Sum ← Sum + Number
Count ← Count + 1
UNTIL Count > 100
PRINT Sum
(a) Find the error in the pseudocode and suggest a correction.
(b) Rewrite the correct algorithm using a more suitable loop structure.
Question 10
The pseudocode algorithm shown should allow numbers to be entered and should allow
50 numbers to be stored in an array.
Count ← 0
REPEAT
INPUT Values[Count]
Count ← Count + 1
UNTIL Count = 0
(a) Explain why the algorithm will never end.
(b) Re-write the original pseudocode so that it terminates correctly and also prevents
numbers below 100 from being stored in the array Values[ ]
(c) Describe how you could change your pseudocode in part (b) so that it prevents numbers
below 100 and above 200 from being stored in the array Values[ ]
Question 11
(a) An algorithm has been written in pseudocode to input the names and marks of 35
students.
The algorithm stores the names and marks in two arrays Name[ ] and Mark[ ]. The highest
mark awarded is found and the number of students with that mark is counted. Both of these
values are output.
Give line numbers where the four errors are to be found in the pseudocode. Suggest a
correction for each error.
(b) Explain how you could extend the algorithm to also find the lowest mark awarded, count
the
number of students with that mark, and output both these values.
Question 12
This section of pseudocode is to be used as a validation check that will continue until a
number between 0 and 499 inclusive is entered.
There are three lines in this pseudocode that contain errors. In each case, state the line
number
to identify the incorrect line and write out the corrected line in full.