CP2 Module 3.1 - Algorithm and Flowchart Examples
CP2 Module 3.1 - Algorithm and Flowchart Examples
Terminal
Pre-defined
Flow Lines
Process
Preparation
COMPUTER PRORAMMING 2 2
Rules in Creating a Flowchart
1. Every flowchart has a START symbol and a STOP symbol.
2. The flow of sequence is generally from the top of the page to the bottom
of the page. This can vary with loops which need to flow back to an entry
point.
3. Use arrow-heads on connectors where flow direction may not be
obvious.
4. There is only one flowchart per page.
5. A page should have a page number and a title.
6. A flowchart on one page should not break and jump to another page.
7. A flowchart should have no more than around 15 symbols(not including
START and STOP).
COMPUTER PRORAMMING 2 3
Flowchart Examples:
Create a flowchart that will display the text "Hello World“ on a screen.
ALGORITHM
1. Define text as a variable with the value of "Hello World“. START
2. Display the value of the variable on the screen.
Flowchart Structure:
• Linear – sequential execution of statements DISPLAY text
from top to bottom
STOP
COMPUTER PRORAMMING 2 4
Flowchart Examples:
START
Draw a flowchart to enter two numbers
through the keyboard and then display the
num1 = 0
difference on the screen. num2 = 0
ALGORITHM
1. Define num1 and num2 as a container for the first and GET num1,
second value. num2
2. Get the value of num1 and num2.
3. Subtract the value of num1 and num2 place in a container
named diff. diff = num1 – num2
4. Display the difference on the screen.
DISPLAY diff
Flowchart Structure:
• Linear – sequential execution of statements
from top to bottom STOP
COMPUTER PRORAMMING 2 5
Flowchart Examples:
Construct a flowchart to enter two number from the START
keyboard and finding the highest value and display it on
the screen. A=0
B=0
ALGORITHM
1. Define A (first value) and B (second value) as variables.
2. Get the value of A and B. INPUT A, B
3. Compare the inputted value of A and B. If A is highest,
then display it otherwise display B.
N Y
A > B
Flowchart Structure:
• Relational – indicates a conditional path DISPLAY B DISPLAY A
that needs for a decision to be made
• Decides whether the result is “True” or
“False”.
COMPUTER PRORAMMING 2
END 6
Flowchart Examples:
Draw a flowchart to display the numbers 1 to 10 from a
single variable.
START
ALGORITHM
1. Define A as a variable with a value of 0.
2. Assign the value of 1 to variable A. A=0
3. Iterate the value of A if less than or equal to 10.
4. Display the value of A
A=1
Flowchart Structure:
• Loop or Iteration – action that performs N Y
repetitive task(s) if conditions are met or is A <= 10
true
END DISPLAY A
COMPUTER PRORAMMING 2 7
COMPUTER PRORAMMING 2 8
Resources:
• Padre, Nilo M. et al. (2016). Programming Concepts Logic Formulation, 1st ed.
Manila: Unlimited Books Library Services & Publishing, Inc.
• How to Create a Flowchart: Logic Formulation. ITS InfoTechSkills (2020).
Retrieved from: https://www.youtube.com/watch?v=YwE6yqi-37Y
• FLOWCHART AND ALGORITHM SAMPLE PROBLEMS. ITS InfoTechSkills (2020).
Retrieved from: https://www.youtube.com/watch?v=BQP2doXjVlQ
• Programming Fundamentals #3: Algorithm & Flowchart. SDFT Solutions (2019).
Retrieved from: https://www.youtube.com/watch?v=szyhF3yvu3k
COMPUTER PRORAMMING 2 9
COMPUTER PRORAMMING 2