Unit 1
Unit 1
FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Pseudocode:
• Input a set of 4 marks
• Calculate their average by summing and dividing
by 4
• if average is below 50
Print “FAIL”
else
Print “PASS”
PSEUDOCODE & ALGORITHM
• Detailed Algorithm
• Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
THE FLOWCHART
A Flowchart
• shows logic of an algorithm
• emphasizes individual steps and their interconnections
• e.g. control flow from one action to the next
FLOWCHART SYMBOLS
Basic
Name Symbol Use in Flowchart
START
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Input
M1,M2,M3,M4
Step 3: if (GRADE <50) then
Print “FAIL”
else
GRADE(M1+M2+M3+M4)/4 Print “PASS”
endif
N IS Y
GRADE<5
0
PRINT PRINT
“PASS” “FAIL”
STOP
EXAMPLE 2
Print
Lcm
STOP
EXAMPLE 3
Algorithm START
• Step 3: Print A
ALxW
Print
A
STOP
EXAMPLE 4
Pseudocode:
• Input the coefficients (a, b, c) of the quadratic equation
• Calculate d
• Calculate x1
• Calculate x2
• Print x1 and x2
EXAMPLE 4
START
• Algorithm:
Input
• Step 1: Input a, b, c a, b, c
b b 4 a c
• Step 2: d sqrt ( ) d sqrt(b x b – 4 x a x c)
• Step 4: x2 (–b – d) / (2 x a)
X2 (–b – d) / (2 x a)
• Step 5: Print x1, x2
Print
x1 ,x2
STOP
DECISION STRUCTURES
Y N
is
A>B
Print Print
A B
IF–THEN–ELSE STRUCTURE
Print Print
A B
RELATIONAL OPERATORS
Relational Operators
Operator Description
> Greater than
< Less than
= Equal to
Greater than or equal to
Less than or equal to
Not equal to
EXAMPLE 5
Input
VALUE1,VALUE2
Y is
N
VALUE1>VALUE2
Print
“The largest value is”,
MAX
STOP
NESTED IFS
Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid