Skip to content

9618 · 9.2

Algorithms — practice questions

Practice and worked examples for 9618 Algorithms. Short previews only — attempt the full question in MarkScheme against the official scheme.

Worked example 1

An algorithm is required to calculate the area of a rectangle. It should take the length and width as inputs, calculate the area, and display the result. Write the algorithm in pseudocode.

Show solution outline

Here is a step-by-step solution following standard pseudocode conventions.

  1. Identify inputs, processes, and outputs:
    • Inputs: Length, Width
    • Process: Area=LengthWidthArea = Length * Width
    • Output: Area
  2. Write the pseudocode:
DECLARE Length : REAL
DECLARE Width : REAL
DECLARE Area : REAL

OUTPUT "Enter the length of the rectangle: "
INPUT Length

OUTPUT "Enter the width of the rectangle: "
INPUT Width

Area <-- Length * Width

OUTPUT "The area of the rectangle is: ", Area

Marks: 1 mark for declaring variables, 1 mark for inputting both values, 1 mark for the correct calculation, 1 mark for outputting the result.

Worked example 2

A cinema offers discounted tickets to customers who are 15 years old or younger, or 65 years old or older. Write an algorithm in pseudocode that inputs a customer's age and outputs either 'Discount applies' or 'Full price payable'.

Show solution outline
  1. Identify inputs, processes, and outputs:
    • Input: Age
    • Process: Check if Age<=15Age <= 15 OR Age>=65Age >= 65
    • Outputs: 'Discount applies' or 'Full price payable'
  2. Write the pseudocode:
DECLARE Age : INTEGER

OUTPUT "Please enter your age: "
INPUT Age

IF Age <= 15 OR Age >= 65 THEN
  OUTPUT "Discount applies"
ELSE
  OUTPUT "Full price payable"
ENDIF

Marks: 1 mark for inputting age, 1 mark for the IF condition with the correct logic (<=15<= 15), 1 mark for including the ORAge>=65OR Age >= 65 condition, 1 mark for the correct outputs in the THEN and ELSE branches.