Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q50 · 9618/22/M/J/24 Q4

Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.

Q509618/22/M/J/24original Q4Structured · 5 marks
Question 4 from 9618/22/M/J/24

Worked solution

(a)

Input the three lengths. Because any one could be the longest, test each one squared against the other two:

PROCEDURE IsRA()
    DECLARE a, b, c : INTEGER
    OUTPUT "Input length of the first side"
    INPUT a
    OUTPUT "Input length of the second side"
    INPUT b
    OUTPUT "Input length of the third side"
    INPUT c
    IF (a * a = (b * b) + (c * c)) OR (b * b = (a * a) + (c * c)) OR (c * c = (a * a) + (b * b)) THEN
        OUTPUT "It is right-angled"
    ELSE
        OUTPUT "Not right-angled"
    ENDIF
ENDPROCEDURE

Procedure heading and ending, with all variables declared [1]

Suitable prompt and input for each of the three lengths [1]

One correct length test [1]

All three length tests (any side may be the longest) [1]

One of two messages output after a reasonable attempt at the test [1]

KEY IDEAThe longest side may be any of the three, so test all three combinations.
TOTAL 5 marks

Official mark scheme

Mark scheme for 9618/22/M/J/24 question 4
VIDEO
▶ Starts at Q4 (32:50)

Starts at Q4 (32:50) · by Pseudocode Pro. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.