Write pseudocode that contains input, process and output

Resources | Subject Notes | Computer Science

9.2 Algorithms: Writing Pseudo-code with Input, Process, and Output

Objective

This section focuses on writing clear and concise pseudo-code that effectively outlines the steps involved in solving a computational problem. The pseudo-code must explicitly define the input, the processing steps, and the expected output.

What is Pseudo-code?

Pseudo-code is an informal way of describing an algorithm. It uses a combination of natural language and structured elements to represent the logic of a program. It's not a programming language, but rather a blueprint for a program.

Key Components of Pseudo-code

  1. Input: The data that the algorithm receives. This is typically specified at the beginning of the algorithm.
  2. Process: The sequence of steps that the algorithm performs to transform the input into the desired output. This is the core of the algorithm.
  3. Output: The result of the algorithm's processing. This is typically specified at the end of the algorithm.

Example: Calculating the Area of a Rectangle

Let's illustrate this with a simple example: calculating the area of a rectangle.

Step # Description Pseudo-code
1 Input: The length and width of the rectangle.

Get the length, $l$, and width, $w$, of the rectangle.

2 Process: Calculate the area.

Area = $l \times w$

3 Output: The calculated area.

Display the calculated area.

More Complex Example: Finding the Maximum of Three Numbers

Now, let's consider a slightly more complex example: finding the maximum of three numbers.

Step # Description Pseudo-code
1 Input: Three numbers, $a$, $b$, and $c$.

Get three numbers, $a$, $b$, and $c$

2 Process: Compare the numbers and find the maximum.

If $a > b$ and $a > c$ then

Maximum = $a$

Else if $b > a$ and $b > c$ then

Maximum = $b$

Else

Maximum = $c$

3 Output: The maximum of the three numbers.

Display the maximum number.

Important Considerations

  • Clarity: Use clear and unambiguous language.
  • Structure: Use indentation to show the structure of the algorithm (e.g., if-then-else blocks, loops).
  • Keywords: Use keywords like "Get", "Display", "If", "Else", "While", "Repeat" to make the pseudo-code easier to understand.
  • Consistency: Be consistent in your notation.

Exercise

Write pseudo-code to calculate the average of two numbers.

Suggested diagram: A simple flowchart showing the input of two numbers, calculation of the sum, and division by 2 to get the average.