Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.
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
ENDPROCEDUREProcedure 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]
▶ 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.