Lecture 2
Lecture 2
Lecture 2
Eventually ends
Start
Yes
No
Stop
Start
1 2
2
Connectors on a different page
Page 1 Page 2
Start
2
1
Stop
Yes 1
No
2
The detail of how the function works
is put in another flowchart.
Read
n1, n2 , n3
Body of a function is
AVRG (result, n1, n2,n3) the same with
normal flowchart
Stop
End terminal
must be a “Return”
Start
N=6
AVRG ( result,n1, n2,n3)
Read
N Sum = 10 + 5 + 6
result = sum/3
Print
average
Output:
Average: 7
Return
Stop
Example:
Start
Read
Length,
Input:
Width Length <- 5
Width <- 3
Area: 15
Print
Area, Perimeter: 16
Perimeter
Stop
Control Structure
Sequence: A series of steps or statements that are executed in
the order they are written in an algorithm.
Programming (1)
18 2021-2022
The Sequence control structure
Display age
end
Format:
if (condition)
then-part
else- then-
else statement(s) statement(s)
else-part
end_if
read age
if (age is greater than 55) Read age
print "Retired"
else
print "Still working" end_if YES
age > 55?
NO
End
Begin
read age
if (age > 55) End
print "Retired"
else
print "Still working"
end_if End
Programming (1)
24 2021-2022
Pseudocodes: The Selection control structure
Programming (1)
26 2021-2022
The Repetition control structure
Specifies a block of one or more statements that are repeatedly
executed until a condition is satisfied.
Format:
while (condition)
loop-body
end_while yes Loop
Condition?
Statement(s)
no
Programming (1)
28 2021-2022
Begin Counter initialisation
number of users giving his age = 1
while (number of users giving his age <= 10)
read the age from the user.
print the user age. Loop condition
number of user giving his age + 1
end_while
Updating counter
End
Begin
users = 1
while (users <= 10)
read age
print age.
users = users + 1
end_while
End
Programming (1)
29 2021-2022
Begin
users = 1
NO
End users <= 10?
YES
read age
print age
users =users + 1
Programming (1)
30 2021-2022
Subsequently..
Begin You can start the
counter with ZERO
number of users giving his age = 0
while (number of users giving his age < 10)
read the age from the user.
print the user age.
number of user giving his age + 1 The loop condition
must less than the
end_while value it requires to
End stop
Begin
users = 0
while (users < 10)
read age
print age. Be
users = users + 1 consistent
end_while
End
Programming (1)
31 2021-2022
Exercise time!!!
Programming (1)
35 2021-2022