Worked example 1
An algorithm is required to calculate the area of a rectangle. It should take the length and width as inputs, calculate the area, and display the result. Write the algorithm in pseudocode.
Show solution outline
Here is a step-by-step solution following standard pseudocode conventions.
- Identify inputs, processes, and outputs:
- Inputs: Length, Width
- Process:
- Output: Area
- Write the pseudocode:
DECLARE Length : REAL
DECLARE Width : REAL
DECLARE Area : REAL
OUTPUT "Enter the length of the rectangle: "
INPUT Length
OUTPUT "Enter the width of the rectangle: "
INPUT Width
Area <-- Length * Width
OUTPUT "The area of the rectangle is: ", Area
Marks: 1 mark for declaring variables, 1 mark for inputting both values, 1 mark for the correct calculation, 1 mark for outputting the result.