Professional Documents
Culture Documents
Module 1
Module 1
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 an algorithm
■ Implementation phase
◻ implement the program in some programming
language
Steps in Problem Solving
■ First produce a general algorithm (one can use
pseudocode)
■ Refine the algorithm successively to get step by
step detailed algorithm that is very close to a
computer language.
Step 1: Start
Step 2: Take pan with water
Step 3: Put pan on the burner
Step 4: Switch on the gas/burner
Step 5: Put magi and masala
Step 6: Give two minutes to boil
Step 7: Take off the pan
Step 8: Take out the magi with the help of
fork/spoon
Step 9: Put the maggi on the plate and
serve it
Step 10: Stop.
ALGORITHM EXAMPLES
Step 1: Start
Step 2: Print “Good Morning‟
Step 3: Stop
ALGORITHM EXAMPLES
Step 1: Start
Step 2: Input length and breadth and
store them as L and B?
Step 3: Multiply by L and B and store it
in area
Step 4: Print area
Step 5: Stop
ALGORITHM EXAMPLES
Write an algorithm to check whether he is eligible
to vote? (more than or equal to 18 years old).
Step 1: Start
Step 2: Input age and store it in age
Step 3: Check age value, if age >= 18 then go
to step 4 else step 5
Step 4: Print “Eligible to vote” and go to
step 6
Step 5: Print “Not eligible to vote”
Step 6: Stop
ALGORITHM EXAMPLES
Write an algorithm to check whether given number is +ve, -ve
or zero.
Step 1: Start
Step 2: Input any number and store it in n.
Step 3: Check n value, if n > 0 then go to
step 5 else go to step 4
Step 4: Check n value, if n < 0 then go to
step 6 else go to step 7
Step 5: Print “Given number is +ve”and go
to step 8
Step 6: Print “Given number is -ve” and go
to step 8
Step 7: Print “Given number is zero”
Step 8: Stop
The Flowchart
■ A graphical representation of the sequence of operations in
an information system or program.
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
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
Example 3
Algorithm START
Print
A
STOP
Flowcharts
■ Flowcharts is a graph used to depict or
show a step by step solution using
symbols which represent a task.
■ The symbols used consist of geometrical
shapes that are connected by flow lines.
■ It is an alternative to pseudocoding;
whereas a pseudocode description is
verbal, a flowchart is graphical in nature.
Principles of Programming - NI July
2005 29
Flowchart Symbols
Terminal symbol - indicates the beginning and
end points of an algorithm.
Statement 1
Statement 2
Statement 3
No Yes
Condition
else- then-
statement(s) statement(s)
yes Loop
Condition
Statement(s)
no
Calculate
Age = current year – birth date
Display
age
End
Read age
End
sum = 0
current_number = 1
NO
current_number <= 10? print sum
YES
sum = sum + current_number End
current_number = current_number +
1
The compiler and interpreter and compiler both are used for
Let’s consider the situation where we need to get 10 student’s age and store
it for some calculation.
Since age is an integer type, we can store it something like below,
or