A student has written an algorithm to calculate the sum of numbers up to a specified limit.
1 SET limit TO 0
2 SET total TO 0
3 SET counter TO 0
4
5 SEND "Enter a positive integer: " TO DISPLAY
6 RECEIVE limit FROM (INTEGER) KEYBOARD
7
8 IF (limit <= 0) THEN
9 SEND "Error: Must be positive" TO DISPLAY
10 ELSE
11 IF (limit = 1) THEN
12 SEND "The sum is 1" TO DISPLAY
13 ELSE
14 FOR counter FROM 1 TO limit DO
15 SET total TO total + counter
16 END FOR
17 SEND "The sum is " & total TO DISPLAY
18 ENDIF
19 ENDIF
Complete the table below to show the output of the algorithm for each given input.
Input (limit) | Expected Output |
|---|---|
| -2 | |
| 1 | |
| 3 |