Resources | Subject Notes | Computer Science
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.
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.
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. |
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. |
Write pseudo-code to calculate the average of two numbers.