Resources | Subject Notes | Computer Science
This section focuses on translating a flowchart into a step-by-step, human-readable algorithm using pseudo-code. Pseudo-code is an informal way of describing an algorithm, using a combination of natural language and structured elements.
A flowchart visually represents the flow of an algorithm using symbols. Pseudo-code provides a textual equivalent, making the algorithm easier to understand and implement in any programming language.
START
/ BEGIN
: Marks the beginning of the algorithm.INPUT
: Represents reading data from the user or a source.OUTPUT
: Represents displaying data to the user or a destination.Process
: Represents a calculation or operation.IF
: Represents a conditional statement.ELSE
: Represents the alternative block in a conditional statement.WHILE
: Represents a loop that continues as long as a condition is true.ENDIF
: Marks the end of an IF
or ELSE
block.ENDWHILE
: Marks the end of a WHILE
loop.RETURN
: Represents the end of an algorithm or a specific section.Consider the following flowchart:
Here's the corresponding pseudo-code:
Step | Pseudo-code |
---|---|
1. START | BEGIN |
2. Input | INPUT number |
3. Process | result = number * 2 |
4. Output | OUTPUT result |
5. END | END |
In this example:
START
.INPUT
s a number
.Process
is performed: the number
is multiplied by 2 and the result is stored in result
.OUTPUT
result
to the user.END
s.Let's consider a flowchart for finding the maximum of two numbers:
The pseudo-code for this flowchart is as follows:
Step | Pseudo-code |
---|---|
1. START | BEGIN |
2. Input | INPUT number1 |
3. Input | INPUT number2 |
4. Process | IF number1 > number2 THEN |
5. Process | maximum = number1 |
6. Else | maximum = number2 |
7. ENDIF | |
8. Output | OUTPUT maximum |
9. END | END |
Explanation:
BEGIN
s.INPUT
s, number1
and number2
.IF
statement checks if number1
is greater than number2
.number1
is assigned to maximum
.number2
is assigned to maximum
.maximum
value is then OUTPUT
ed.END
s.