Algorithm Flowchart PDF
Algorithm Flowchart PDF
DECISION
PRINTOUT
SUB-ROUTINE
Change to the
Algorithm
movie channel
1. Switch on the TV and
UBC sets
2. Change to the required
movie channel
Sit down
Watch movie
3. Sit down and watch the
movie
End
204112 Structured Programming 5
Start
Set Action as GO
Else
Set Action as STOP Output Action
3. Print Action
End
Inputs Outputs
Problem Statement
Read a number from the keyboard. Input N
Check and output if a given
number N is ODD or EVEN Remainder <- N modulo 2
Algorithm Yes No
Remainder = 0 ?
1. Read N
2. Set Remainder as N modulo 2 Answer <- EVEN Answer <- ODD
3. If Remainder is equal to 0 then
Set Answer as EVEN
Else Output Answer
Set Answer as ODD
4. Print Answer
End
Inputs Outputs
No
Problem Statement Gender = Male ? Input Status
Print Title for a person (Either Mr. or
Miss. or Mrs.). You are to read the Yes
gender (and status if needed).
Status = Married ?
Title <- Mr.
Algorithm
1. Read Gender Yes No
2. If Gender is MALE then
Title is Mr.
Else Title <- Mrs. Title <- Miss
Read Status
If Status is MARRIED then
Title is Mrs.
Else
Title is Miss.
Output Title
3. Print Title
End
204112 Structured Programming 13
Example 6 – Input/Output Samples
Inputs Outputs
Initialize X <- 0
Problem Statement
Print 1 to 20 Increment X by 1
Print X
Algorithm
1. Initialize X as 0
2. Increment X by 1 Yes
` X < 20
3. Print X
4. If X is less than 20 then
go back to Step 2 No
End
ExtractHOURS
Problem Statement Extract MINUTES
Given computer time is stored in 24
hours format, you are to print the No
time in AM/PM format HOURS = 0 ? 1 <= HOURS <= 12
Inputs Outputs
YES NO
MONTH = 2 ?
Problem Statement
Read the Month (and Year, if needed) Input YEAR
and print the number of days in
that month
Month = 2 Days = 29
Year = 2004
Month = 2 Days = 28
Year = 2005
Month = 10 Days = 31
Month = 4 Days = 30
NO
Phone working ?
YES
YES
Line is busy ?
NO
YES NO
Friend found ?
Example 12 Input N
Output Error
YES NO
CHANGE < 10 ?
YES NO
CHANGE < 5 ?
NO
Any more unprocessed numbers ?
YES
YES NO
COUNT = 0 ?
List = 4 Average = 4
Algorithm
1. Initialize MINX, MINY, MAXX, MAXY using the 1st Vertex
2. Retrieve the next unevaluated vertex (X, Y)
3. If X < MINX, then set MINX as X
4. If X > MAXX, then set MAXX as X
5. If Y < MINY, then set MINY as Y
6. If Y > MAXY, then set MAXY as Y
7. If all vertices have not been evaluated then go back to step 2
8. Set LENGTH as MAXX – MINX
9. Set HEIGHT as MAXY – MINY
YES
X < MINX Set MINX <- X
NO
B
YES
X > MAXX Set MAXX <- X
NO
Set LENGTH <- MAXX - MINX
Set HEIGHT <- MAXY - MINY
YES
Y < MINY Set MINY <- Y
End NO
YES
Y > MAXY Set MAXY <- Y
NO
NO YES
B Any unevaluated vertex left ? A
204112 Structured Programming 30
Example 14 – Input/Output Samples
Inputs Outputs
4 sides (2,2) (5,3) (3,5) (6,2) Length = 4
Height = 3
3 sides (1,2) (5,3) (8, -2) Length = 7
Height = 5
5 sides (2,5) (7,1) (3,2) (-3, -5) Length = 10
(4,1) Height = 10