You are on page 1of 20

ALGORITHM AND FLOW CHARTS

Lesson 5
WHAT IS A PROBLEM?

• A question
• An unexpected situation
• A doubtful situation
• Needs to be solved
PROCESS OF PROBLEM SOLVING

• Get a good understanding of the problem


• Analyze the problem
• Understand its input, process and outcome
Input • Things to be included to solve the problem

• Guidelines to be followed to solve the


Proces problem
s
• The result you get after solving
Output the problem
EXAMPLES

Problem –Adding two numbers

• Input – Two numbers


• Process – Total= 1st number + 2nd number
• Output – Total
Problem – Making a cup of milk tea

• Input – boiled water, sugar, milk, tea leaves,


• Process – 1. Putting the tea leaves in the filter
2. Pouring boiled water to the teapot through the filter
3. Adding some sugar and milk to the tea pot
4. Stirring it well with a spoon
5. Pouring milk tea into the cup
• Output – cup of milk tea
Problem – Calculate the Perimeter of the rectangle

• Input – Length and Width of the rectangle


• Process – Calculating the Perimeter
Perimeter = Length + Length + Width+ Width
• Output – Perimeter
WHAT IS AN ALGORITHM ?

• A method that includes all the steps of solving a


problem in order is known as an algorithm.
WRITING ALGORITHM

Problem – Calculate the Area of the rectangle

Start
Get the length of the rectangle
INPUT
Get the width of the rectangle
PROCESS
Area = length x width
Display the area of the rectangle OUTPUT

End
Problem – Make Fruit Salad

Start
Get fruits
Wash the fruits
Cut the fruits into small pieces
Put pieces into a bowl
Add sugar, salt and lime juice
Mix it
Serve the fruit salad
End
WHAT IS A FLOWCHART?

• A flowchart is a graphical representation of the


algorithmic steps

• Standard symbols are used to show each action


FLOW CHART SYMBOLS

Used to indicate the START


and the END

Used to indicate the INPUT


and the OUTPUT
Used to indicate the
PROCESS

YES Used to indicate a


CONDITION, an instance of
decision making
NO

Used to indicate the


DIRECTIONS of the data
flow.
Find the area of a START

rectangle
INPUT LENGTH OF THE
RECTANGLE

INPUT WIDTH OF THE


RECTANGLE

AREA= LENGTH * WIDTH

DISPLAY AREA

END
Find the largest number START

INPUT NUMBER 1

INPUT NUMBER 2

Is number 1 YES
greater than
DISPLAY NUMBER 1
number 2

NO

DISPLAY NUMBER 2

END
DRAW A FLOW CHART TO EXPLAIN A SIMPLE
SEQUENTIAL PROCESSES

• Making a cup of milk tea


• Adding two numbers
• Calculate the Perimeter of the rectangle
• Sasiru loves receiving birthday presents. He receives lot of presents on
his birthday. His friends say that he is very lucky. Draw a flowchart to
show this incident.
START
Opening the presents

IS TODAY
MY NO
BIRTHDAY
?

YES

OPEN THE PRESENT

YES MORE
PRESENTS
?

NO

END
• Enuri loves shopping. She saw two beautiful frocks on
www.chenaradodge.lk website. She ordered both frocks but, one frock
was displayed as “Available” where as the other was displayed as “out of
stock”.
• Ordering a pizza online

You might also like