Exam-style question
Try this first
The following pseudocode algorithm aims to find the largest number in a list of `N` numbers provided by the user. There is one logical error in the algorithm. ```pseudocode FUNCTION FindLargest(N) SET largest = 0 FOR i FROM 1 TO N OUTPUT "Enter number " + i + ": " INPUT current_number IF current_number > largest THEN SET largest = current_number ENDIF ENDFOR OUTPUT "The largest number is: " + largest ENDFUNCTION ``` Identify the logical error and rewrite the pseudocode with the correction. Explain why your correction fixes the error. [5 marks].
Answer and explanation
Concise answer
**Logical Error Identification:** The initialisation of `largest` to `0` is a logical error.
Why this is correct
1 mark for identifying the error: `largest` initialised to `0` may fail for negative numbers. 1 mark for correctly explaining *why* it is an error (e.g., if all inputs are negative). 1 mark for correctly initialising `largest` with the first user input (or negative infinity). 1 mark for adjusting the loop to start from the second input (if initialising with first input).
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
