Unit 7: Algorithm and Flowchart
7.1 Understanding the Problem
7.1.1 Describe the following steps of the problem-solving process:
a. Define the problem
b. Analyse the problem
c. Planning the solution of the problem
d. Find candid solutions of the problem
e. Select the best solution
7.2 Algorithm
7.2.1 Define an algorithm. 7.2.2 Describe the following four essential parts of an algorithm:
a. Inputs
b. Processing
c. Decision
d. Outputs
7.1 Understanding the Problem
When we solve a problem using a computer (for example in C language), we follow some steps. These steps help us write correct programs.
7.1.1 Steps of the Problem-Solving Process
a. Define the Problem
This is the first and most important step.
To define the problem means:
-
Clearly understand what we have to do
-
Know what the user wants
-
Know what result is required
Simple Meaning:
Before writing any program, we must clearly say:
"What is the problem?"
Example:
Problem:
"Write a program to calculate the average of three numbers."
Here the problem is clearly defined:
-
Input: 3 numbers
-
Output: Average
If we don’t define the problem properly, the program may give wrong results.
b. Analyse the Problem
After defining the problem, we must analyze it.
To analyze means:
-
Break the problem into smaller parts
-
Identify:
-
What are the inputs
-
What processing is required
-
What will be the output
-
Example:
Problem: Calculate average of 3 numbers.
Analysis:
-
Inputs → Number1, Number2, Number3
-
Process → Add them and divide by 3
-
Output → Average
In C language, this means:
-
We need 3 variables for input
-
1 variable for average
-
Use formula:
c. Planning the Solution of the Problem
Now we plan how to solve the problem.
This includes:
-
Writing algorithm
-
Drawing flowchart
-
Deciding variables
-
Deciding formulas
Simple Meaning:
We decide:
"How will we solve the problem step by step?"
Example Plan:
-
Start
-
Input 3 numbers
-
Add numbers
-
Divide by 3
-
Display average
-
Stop
Planning helps us avoid errors while writing C program.
d. Find Candidate Solutions of the Problem
Sometimes a problem can be solved in more than one way.
Candidate solutions mean:
-
Different possible methods to solve the same problem.
Example:
Problem: Check whether a number is positive or negative.
Method 1:
-
Use
if (num > 0)
Method 2:
-
Use ternary operator:
Both are correct solutions. These are candidate solutions.
e. Select the Best Solution
After finding different solutions, we select the best one.
Best solution means:
-
Easy to understand
-
Uses less memory
-
Runs faster
-
Simple logic
Example:
Between:
-
Complex nested conditions
-
Simple
if-else
We select:
✔ Simple if-else because it is easier for students to understand.
7.2 Algorithm
7.2.1 Define an Algorithm
Definition:
An algorithm is a step-by-step procedure to solve a problem.
It is written in simple English language.
It tells:
-
What to do
-
In what order to do
Before writing C program, we first write algorithm.
Example Algorithm:
Problem: Add two numbers
-
Start
-
Input number1
-
Input number2
-
sum = number1 + number2
-
Display sum
-
Stop
This is an algorithm.
7.2.2 Four Essential Parts of an Algorithm
Every algorithm has four important parts.
a. Inputs
Inputs are:
-
The data given to the program
-
Values entered by the user
In C language:
We use:
Example:
If we calculate area of rectangle:
-
Input → length and width
b. Processing
Processing means:
-
Performing calculations
-
Applying formulas
-
Doing logical operations
In C language:
We use:
-
Arithmetic operators (+, -, *, /)
-
Assignment operator (=)
Example:
This step is called processing.
c. Decision
Decision means:
-
Making a choice
-
Checking conditions
In C language:
We use:
-
if -
if-else -
switch
Example:
If we check even or odd:
This is decision making.
d. Outputs
Output means:
-
The final result of the program
-
What we show to the user
In C language:
We use:
Example:
✅ Summary
Problem Solving Steps:
-
Define the problem
-
Analyse the problem
-
Plan the solution
-
Find possible solutions
-
Select best solution
Algorithm:
-
A step-by-step method to solve a problem.
Four Parts of Algorithm:
-
Input
-
Processing
-
Decision
-
Output
a. Performing arithmetic, relational, and logical operations
b. Calculating the volume of geometrical shapes
c. Finding the area of various geometrical shapes
d. Converting from one unit to another unit of physical quantities
e. Finding the maximum and minimum from input values
f. Perfor
ming the counting and totaling on given values g. Applying the repetition process
h. Applying the selection process
7.3 Flowchart
7.
7.3.2 Describe the importance of a program flowchart for solving a problem.
7.3.3 Identify the flowchart symbols for the following:
a. Input
b. Process
c. Decision making
d. Outputs
e. Terminator/terminal point
f. Connectors
7.3.1 Define a Program Flowchart
Definition:
A program flowchart is a diagram that shows the steps of a program using symbols.
It shows:
-
What step comes first
-
What step comes next
-
How the program flows
-
Where decisions are made
A flowchart uses standard symbols connected with arrows.
Simple Meaning:
An algorithm is written in words.
A flowchart shows the same steps in picture form (diagram form).
Example:
Problem: Add two numbers
Algorithm:
-
Start
-
Input two numbers
-
Add numbers
-
Display result
-
Stop
Flowchart shows the same steps using symbols and arrows.
7.3.2 Importance of a Program Flowchart
Flowchart is very important before writing a C program.
✅ 1. Makes the Problem Easy to Understand
When we see the problem in diagram form, it becomes easier to understand.
Instead of reading long text, we can understand quickly by looking at the symbols.
✅ 2. Helps in Planning the Program
Flowchart helps programmers:
-
Arrange steps in correct order
-
Avoid missing steps
-
Remove logical mistakes
Before writing code in C, drawing a flowchart reduces errors.
✅ 3. Makes Debugging Easy
If there is a mistake:
-
We can easily find it in the flowchart
-
Then correct the logic
This saves time.
✅ 4. Improves Communication
Flowcharts help:
-
Teachers explain programs
-
Students understand logic
-
Programmers discuss ideas
Even a person who does not know C language can understand the flowchart.
✅ 5. Converts Easily into C Program
Each symbol in flowchart matches C statements:
-
Input symbol →
scanf() -
Process symbol → calculations
-
Decision symbol →
if-else -
Output symbol →
printf()
7.3.3 Flowchart Symbols
Now we will identify and explain important symbols.
a. Input Symbol
Shape:
Parallelogram
Use:
Used to take input from user.
C Language Example:
Example in Flowchart:
Input number
b. Process Symbol
Shape:
Rectangle
Use:
Used for:
-
Calculations
-
Assignments
-
Processing data
C Language Example:
c. Decision Making Symbol
Shape:
Diamond
Use:
Used when condition is checked.
It has:
-
Two outputs → Yes / No
-
True / False
C Language Example:
d. Output Symbol
Shape:
Parallelogram (same as input)
Use:
Used to display result.
C Language Example:
e. Terminator / Terminal Point
✅ Summary Table
| Symbol | Shape | Used For | C Language Example |
|---|---|---|---|
| Input | Parallelogram | Take input | scanf() |
| Process | Rectangle | Calculation | sum = a + b |
| Decision | Diamond | Condition checking | if-else |
| Output | Parallelogram | Display result | printf() |
| Terminator | Oval | Start / Stop | Start, End |
| Connector | Circle | Join flow lines | Continue |
7.3.4 Draw flowchart
7.3.5 Complete the trace table for a given flowchart.





