CSC 1102: PROGRAMMING LANGUAGE 1
FLOW CHARTS
Sarwar Morshed
American International University
ALGORITHMS AND FLOWCHARTS
A typical programming task can be divided into two
phases:
Problem solving phase
produce an ordered sequence of steps that describe solution
of problem
this sequence of steps is called an algorithm
Implementation phase
implement the program in some programming language
FLOW CHARTS
A flow chart can be used to:
Define and analyse processes.
Build a step-by-step picture of the process for analysis, discussion,
or communication.
Define, standardise or find areas for improvement in a process.
FLOW CHARTS
Symbols for drawing a flowchart:
Start or End of the program / Terminator.
Terminator
This symbol represents the beginning and end point in a program.
We use start and stop option in it.
Input or output operation
Input / Output Symbol
This symbol is used to take any input or output in the algorithm.
Computational Steps or Processing Function of a program
Process Symbol
A rectangle indicates the processing, calculation and arithmetic
operations
Decision Making and Branching
Decision Symbol
It is used when we want to take any decision in the program.
Connector or joining of two parts of program
Connector Symbol
This symbol is used to connect the various portion of a flow chart.
This is normally used when the flow chart is split between two
pages
Magnetic Tape
Magnetic Disk
HYBRID
For Display
Flow lines
Data Flow Symbol
This symbol is used to display the flow of the program. It shows
the path of logic flow in a program.
Annotation (foot note)
Guidelines in flowcharting -
In drawing a proper flowchart, all necessary
requirements should be listed out in logical order.
The flowchart should be clear, neat and easy to follow.
There should not be any room for ambiguity in
understanding the flowchart.
The usual direction of the flow of a procedure or
system is from left to right or top to bottom.
…Guidelines in flowcharting -
Only one flow line should come out from a process symbol.
OR
…Guidelines in flowcharting -
Only one flow line should enter a decision symbol, but two or
three flow lines, one for each possible answer, should leave the
decision symbol.
…Guidelines in flowcharting –
Only one flow line is used in conjunction with terminal
symbol.
Start Stop/End
…Guidelines in flowcharting –
Write within standard symbols briefly. As necessary, you
can use the annotation symbol to describe data or
computational steps more clearly.
This is confidential data
…Guidelines in flowcharting –
In case of complex flowchart, it is better to use
connector symbols to reduce the number of flow lines.
Avoid the intersection of flow lines.
Ensure that the flowchart has a logical start and finish.
It is useful to test the validity of the flowchart by
passing through it with a simple test data.
Advantages Of Using Flowcharts :
Communication: Flowcharts are better way of communicating the logic of a
system to all concerned.
Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way.
Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes.
Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.
Proper Debugging: The flowchart helps in debugging process.
Efficient Program Maintenance: The maintenance of operating program
becomes easy with the help of flowchart. It helps the programmer to put efforts
more efficiently on that part
Limitations of using Flowcharts :
1. Complex logic: Sometimes, the program logic is
quite complicated.
2. Alterations and Modifications: Alterations may
require re-drawing completely.
3. Reproduction: As the flowchart symbols cannot
be typed, reproduction of flowchart becomes a
problem.
DECISION STRUCTURES
The expression A>B is a logical expression
it describes a condition we want to test
ifA>B is true (if A is greater than B) we take the
action on left
print the value of A
ifA>B is false (if A is not greater than B) we take the
action on right
print the value of B
DECISION STRUCTURES
Y N
is
A>B
Print Print
A B
IF–THEN–ELSE STRUCTURE
The structure is as follows:
If condition then
true alternative
else
false alternative
endif
IF–THEN–ELSE STRUCTURE
The algorithm for the flowchart is as follows:
If A>B then
print A
else
Y N
print B is
A>B
endif
Print Print
A B
SOME REAL LIFE EXAMPLES
DO YOU WANT TO CROSS THE ROAD?
START
Yes No
Are you at the
road side?
Look left
Yes
Wait 2 secs
Look right
Are there any
cars coming ?
No
Cross the road
STOP
DO YOU WANT TO GET UP AFTER ALARM RINGS?
START
Alarm rings
Wait 5 mins
Are you at ready
to get up?
No
Hit snooze button
Yes
Climb out of bed
STOP
LETS GO TO SOME C PROGRAM
EXAMPLES
main() --------------Function name
{ ------------Start of Program
….
…. -------- Program statements
….
} --------------- End of Program
29
CONTD…
/* Filename : hello.c
Description : This program prints the greeting
“Hello, World!”
*/
#include <stdio.h>
#include <stdio.h>
int main(void)
void main( ) {
{ printf ( “Hello, World!\n” ) ;
printf ( “Hello, World!\n”); return 0 ;
getch(); }
}
30
FLOWCHART FOR HELLO.C
An oval denotes either
int main () the start or the end of
{ the program, or a halt
printf("Hello, world!\n");
operation within the
}
Start program (which we’ll
learn about later).
A parallelogram
Output “Hello, world!”
denotes either an input
operation or an output
operation.
End
An arrow denotes the
flow of the program.
31
EXAMPLE 1 - ADD THREE NUMBERS
A program is required to read three numbers, add them
together and print their total.
Defining diagram
Input Processing Output
Number1 Read three numbers Total
Number2 Add number together
Number3 Print total number
SOLUTION Start
Read
Number1
Number2
number3
Add numbers to total
Print total
Stop
EXAMPLE 2
Write an algorithm and draw a flowchart to convert the
length in feet to centimeter.
Pseudo code:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying LFT
with 30
Print length in cm (LCM)
Algorithm Flowchart
Step 1: Input Lft
START
Step 2: Lcm Lft x 30
Step 3: Print Lcm Input
Lft
Lcm Lft x 30
Print
Lcm
STOP
EXAMPLE 3
Write an algorithm and draw a flowchart that
will read the two sides of a rectangle and
calculate its area.
Pseudocode
Input the width (W) and Length (L) of a
rectangle
Calculate the area (A) by multiplying L with W
Print A
Algorithm START
Step 1: Input W,L
Step 2: AL x W Input
W, L
Step 3: Print A
ALxW
Print
A
STOP
Example 4.
Draw a flowchart to find the sum of first 50 natural
numbers.
Example 5
Draw a flowchart to find the largest of three numbers A,B and C.
Example 5
Write an algorithm to determine a student’s final grade and
indicate whether it is passing or failing. The final grade is
calculated as the average of four marks.
EXAMPLE 5
START
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Input
M1,M2,M3,M4
Step 3: if (GRADE <50) then
Print “FAIL”
else
GRADE(M1+M2+M3+M4)/4 Print “PASS”
else if
N IS Y
GRADE<5
0
PRINT PRINT
“PASS” “FAIL”
STOP
THANK YOU.