0%
0 / 15 answered
Developing Procedures Practice Test
•15 QuestionsQuestion
1 / 15
Q1
Based on the scenario, a student writes a procedure to find the maximum value in a non-empty list of integers. Input: list nums (length 1 to 50,000). Output: the largest integer in the list. Constraint: must work for negative numbers.
PROCEDURE maxValue(nums)
max ← 0
FOR EACH n IN nums
IF n > max
max ← n
ENDIF
ENDFOR
RETURN max
ENDPROCEDURE
Which step is necessary to ensure the procedure works correctly for all valid inputs?
Based on the scenario, a student writes a procedure to find the maximum value in a non-empty list of integers. Input: list nums (length 1 to 50,000). Output: the largest integer in the list. Constraint: must work for negative numbers.
PROCEDURE maxValue(nums)
max ← 0
FOR EACH n IN nums
IF n > max
max ← n
ENDIF
ENDFOR
RETURN max
ENDPROCEDURE
Which step is necessary to ensure the procedure works correctly for all valid inputs?