Week 3
Week 3
Definition of flowchart
Description of flowchart symbols
Solving simple programming table with flowcharts
The flowchart
A flowchart is a pictorial representation of an Algorithm or of the plan of solution
of a problem. It indicates the process of solution, the relevant operations and
computations, point of decision and other information that are part of the solution.
Flowcharts are of particular importance for documenting a program. Special
geometrical symbols are used to construct flowcharts. Each symbol represents an
activity. The activity could be input/out of data, computation/processing of data,
taking a decision, terminating the solution, etc. The symbols are joined by arrows
to obtain a complete flowchart.
Flowchart is a representation of the algorithm using standard symbols. Each
symbols has a new function.
The Algorithm steps determine which symbol to use to represent it in the flow each
step is linked to another step by using the directional arrows.
Example 2
Draw a flowchart to find the average of four numbers stored in variables A,B,C,D.
when the value of A is zero, no averaging is to be done.
Example 3
Write an algorithm and draw a flowchart that will read the two sides of a rectangle
and calculate its area.
Solution
Pseudo code
• Input the Width (w) and Length(L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A.
Algorithm
Step 1: Input W, L
Step 2: A← L * W
Step 3: Print A.
Example 4
Write an algorithm and draw a flowchart that will calculate the roots of a quadratic
equation.
ax2+ bx + c = 0
Hint: d = SQrt(b2– 4ac), and the roots are:
X1 = (-b + d)/2a and X2 = (b – d)/ 2a
Solution
Pseudo code
• Input the coefficients (a, b, c) of the quadratic equation
• Calculated
• Calculate X1
• Calculate X2
• Print X1 and X2
Step 1: Input a, b, c
Step 2: d ← Sqrt (b * b – 4 * a * c)
Step 3: X1 ← ( - b + d)/ (2 * a)
Step 4: X2 ← (- b – d)/ (2 * a)
Step 5: Print X1, X2
Start
Input
a, b, c
d ← Sqrt + (b * b – 4*a*c
X1 ← (-b + d)/ (2*a)
X2 ← (-b – d) / (2* a)
Print
X1, X2
Stop
Flowchart
Uses of flowcharts
1 It gives us an opportunity to see the entire system as a whole.
2 It makes us to examine all possible logical outcomes in any process.
3 It provides a tool for communicating i.e a flowchart helps to explain the system
to others.
4 To provide insight into alternative solutions.
5 It allows us to see what will happen if we change the values of the variable in the
system.