BEGIN
READ n
SET sum = 0
FOR i = 1 TO n DO
sum = sum + i
END FOR
PRINT sum
END
BEGIN/END, IF/THEN/ELSE, WHILE, FOR, READ/PRINT used consistently but looselyWhen asked to "write an algorithm" in the CS-optional paper, pseudo code (not full C++ syntax) is usually the expected answer format — focus on clear structured steps over compilable syntax.
2026, Paper I, Q3(c) (8 marks) — Write pseudocode to reverse an array using pointers.
Function ReverseArray(arr, n):
left <- pointer to arr[0] // first element
right <- pointer to arr[n-1] // last element
while left < right: // pointers haven't crossed
temp <- *left
*left <- *right
*right <- temp
left <- left + 1
right <- right - 1
return arr
Key reasoning points:
[left, right] is already correctly reversed.int* left = arr; int* right = arr + n - 1; inside the same swap-and-converge while loop.