Flow Chart
A flow chart is useful because it helps us understand the flow of execution of a program easily.
Why Do We Use Flow Charts?
- To represent an algorithm visually.
- To understand the order of program execution.
- To make complex problems easier to understand.
- To find mistakes in an algorithm before writing the actual program.
- To explain a program to other people.
Common Flow Chart Symbols
| Symbol | Name | Purpose |
|---|---|---|
| Oval | Start / Stop | Shows the beginning or end of a program. |
| Rectangle | Process | Represents an operation or calculation. |
| Parallelogram | Input / Output | Used to read input or display output. |
| Diamond | Decision | Used when a condition needs to be checked. |
| Arrow | Flow Line | Shows the direction of execution. |
Input and Output
Input
Examples:
- Entering a student’s name
- Entering a number
- Entering marks
- Entering age
Output
Examples:
- Displaying a number
- Displaying the sum of two numbers
- Displaying a student’s result
Example 1: Add Two Numbers
Let’s create an algorithm and pseudocode to add two numbers: 12 and 24.
Algorithm
- Start the program.
- Reserve memory space with the name a.
- Store the value 12 into a.
- Reserve another memory space with the name b.
- Store the value 24 into b.
- Reserve another memory space with the name sum.
- Add the values in a and b and store the result in sum.
- Display the value of sum on the monitor.
- Stop the program.
Pseudocode
1. START
2. DECLARE a
3. a := 12
4. DECLARE b
5. b := 24
6. DECLARE sum
7. sum := a + b
8. WRITE "sum =", sum
9. STOP
Explanation
The program first creates three variables: a, b, and sum.
The values 12 and 24 are stored in a and b. Then the program calculates:
sum = a + b
Therefore: sum = 12 + 24 = 36
Output
Flow of Execution
Example 2: Get a Number from the User
In the previous example, the values were already given. Now let’s create an algorithm that allows the user to enter a number.
Algorithm
- Start the program.
- Reserve some memory space in RAM to store a number and assign the name a to it.
- Show a message to the user asking them to enter a number.
- Take the number entered by the user and store it in a.
- Display the value stored in a on the monitor.
- Stop the program.
Pseudocode
1. START
2. DECLARE a
3. WRITE "Enter a number"
4. READ a
5. WRITE "Value of a =", a
6. STOP
Explanation
READ is used to take input from the user.
WRITE is used to display a message or result to the user.
If the user enters 50, the value 50 is stored in the variable a.
Sample Output
50
Value of a = 50
Important Pseudocode Commands
| Command | Meaning | Example |
|---|---|---|
| START | Begins the algorithm. | START |
| STOP | Ends the algorithm. | STOP |
| DECLARE | Creates a variable. | DECLARE a |
| READ | Takes input from the user. | READ a |
| WRITE | Displays information or output. | WRITE a |
| := | Assigns a value to a variable. | a := 12 |
Algorithm → Pseudocode → Flow Chart
These three are different ways of representing the same problem.
- Algorithm: Written step-by-step instructions.
- Pseudocode: A simple, programming-like representation of the algorithm.
- Flow Chart: A visual representation using standard symbols.
Simple Example
Problem: Read a number and display it.
| Representation | Solution |
|---|---|
| Algorithm |
1. Start 2. Declare a 3. Ask the user to enter a number 4. Read a 5. Display a 6. Stop |
| Pseudocode |
START DECLARE a WRITE “Enter a number” READ a WRITE “Value of a =”, a STOP |
| Flow Chart | Start → Declare a → Input a → Display a → Stop |
Practice Questions
Write the algorithm, pseudocode, and flow chart for each of the following programs.
Practice: Convert Previous Programs
- Pseudocode
- Flow chart
Quick Revision
- A flow chart is a pictorial representation of an algorithm.
- Standard symbols are used to represent different activities.
- Input collects data from the user.
- Output displays information or results.
- DECLARE creates a variable.
- READ takes input.
- WRITE displays output.
- := is used for assigning a value to a variable.
- START begins an algorithm.
- STOP ends an algorithm.