Algorithms and Flowcharts
Algorithms and Flowcharts
FLOWCHARTS
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 analgorithm
Implementation phase
implement the program in some programming language
STEPS IN PROBLEM
SOLVING
First produce a general algorithm (one can
usepseudocode )
Refine the algorithm successively to get
step by step detailedalgorithm that is very
close to a computer language.
Pseudocode is an artificial and informal
language that helps programmers develop
algorithms. Pseudocode is very similar to
everyday English.
PSEUDOCODE &
ALGORITHM
Example 1: Write an algorithm to determine a student’s final
A Flowchart
9
FLOWCHART SYMBOLS
Basic
FLOWCHART SYMBOLS
Terminal symbol - indicates the beginning and
end points of an algorithm.
11
FLOWCHART SYMBOLS
CONT… Selection symbol - shows a selection process
for two-way selection.
12
FLOWCHART – SEQUENCE CONTROL
STRUCTURE
Statement 1
Statement 2
Statement 3
13
FLOWCHART – SELECTION CONTROL
STRUCTURE
No Yes
Condition
else- then-
statement(s) statement(s)
14
FLOWCHART – REPETITION CONTROL
STRUCTURE
yes Loop
Condition
Statement(s)
no
15
EXAMPLE
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”
endif
N IS Y
GRADE<50
PRINT PRINT
“PASS” “FAIL”
STOP
EXAMPLE 2
Write an algorithm and draw a flowchart to convert the length
in feet to centimeter.
Pseudocode:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying LFT with 30
Print length in cm (LCM)
EXAMPLE 2
Flowchart
Algorithm START
Print
Lcm
STOP
EXAMPLE 3
ALxW
Print
A
STOP
FLOWCHART – EXAMPLE 1
Begin
Calculate
Age = current year – birth date
Display
age
End
21
FLOWCHART – EXAMPLE 2
Begin
Read age
End
22
FLOWCHART – EXAMPLE 5
Begin
sum = 0
current_number = 1
NO
current_number <= 10? print sum
YES
End
sum = sum + current_number
current_number = current_number + 1
23
EXERCISES: ALGORITHM & FLOWCHART
two numbers. If the sum is below or equal to twenty, two numbers will
be entered again. If the sum is above 20, it will display the sum.
LAB ACTIVITY: ALGORITHM &
FLOWCHART
4) Create an algorithm and a flowchart that will output the largest
given number.
4. Create an algorithm and a flowchart that will output all the prime