Algorithm Advanced Manual
Algorithm Advanced Manual
Pseudo Codes
Grade 12
Circle Connection
Inputs Input a , b
Calculations Sum = a + b
Stop Stop
• Sequence
• Selection
• Iteration
SEQUENCE is a linear progression
where one task is performed
START
sequentially after another.
Statement 1
Statement 2
Statement 3
STOP
Start
Sum = 0
Average = 0
average of Input
Number2
two numbers
Sum = Numbe1 + Number2
Average = Sum / 2
Display
Sum, Average
Stop
SELECTION - there may be
alternative steps that could be taken
subject to a particular condition
Get
Length
Get
Width
Is Length Y
equal to
Width ?
N
Display
“Figure is Square”
Stop
Input the length and width of a quadrilateral and
state whether it is a square or a rectangle.
Start
Y
Is Length equal
Width ?
Display Display
N
“Figure is Rectangle” “Figure is Square”
Stop
Connectors
When a flowchart is too long to fit on a page
and is to be continued on another page a
connector symbol is used
Start
Add number to
value of total
Set value of
Counter to 0 Increment
counter by 1
Set value of
Total to 0
B
Is N
Counter B
Get Number = 10?
Y
A
Write total
Stop
ITERATION - certain steps may need to
be repeated while, or until, a certain
condition is true
• While
• For
• Repeat
while
Start loop
false
Condition
?
true
End loop
Statement
sequence
Start
counter = 0
of 10 numbers No
Counter< 10
?
yes
Display total
Get Number
Stop
total = total+number
counter=counter+1
For
Start For
Control_variable false
< end_value
?
true
Statement-sequence
Control_variable = Control_variable+1
End For
Display the numbers 1, 2, 3, 4, 5, ….., 100
Start
no = 1
false
no <=
100
true Stop
Display no
no = no + 1
Example -7
• Enter marks of 4 subjects and find
the average. If the average is less
than 50 then display “pass” else
display “fail”.
Start
average = 0
average = ( m1 + m2 + m3 + m4 ) /4
IF Average < 50
false
true
Display
N
Display “Pass”
“Fail”
Stop
Example -8
discount = 0
Input Bill_Amount
false
IF Bill_Amount
> = 5000
true
Discount = Bill_Amount * 0.10 Discount = Bill_Amount * 0.05
Display
Discount
Stop
Example - 9
Commission = 0, Tot_Salary = 0
Input Sales_Amount
false
IF
Sales_Amount
> = 50000
true
Commission = Sales_Amount * 0.25 Commission = Sales_Amount * 0.10
Display Tot_Salary
Stop
• Pseudo codes use every day language…to prepare a
brief set of instructions…in the order…in which they
will appear in a finished program
statement 1
Statement 1
statement 2
statement 3
Statement 2
Statement 3
STOP
Example - 10
INPUT a
INPUT b
sum = a + b
OUTPUT sum
• Compare and Select One of Two
Alternative Actions
• Select one path according to the condition
– IF …. THEN
• If the condition is true do the statements inside IF
• No operation if the condition is false
– IF …. THEN …. ELSE
• If the condition is true do the statements inside IF
• If the condition is false do the statements inside ELSE
IF
Pseudocode:
True
Condition?
False IF condition
THEN
sequence-1(statements)
ELSE
Statement sequence 1 Statement sequence 2
sequence-2(statements)
ENDIF
ENDIF
IF <condition> THEN • Example1:
sequence 1 IF a>0 THEN
ENDIF Print a
END IF
• Example2:
IF <condition> THEN
IF a>b THEN
sequence 1
Print a
ELSE
ELSE
sequence 2
Print b
ENDIF
END IF
Example-11
• Write a pseudo code that inputs two
numbers (a and b) and output the largest
number.
INPUT a
INPUT b
IF a < b THEN
OUTPUT b
ELSE
OUTPUT a
END IF
– WHILE … ENDWHILE
While
While
Pseudocode:
WHILE <Condition>
false
Statement- Sequence
Condition
? END WHILE
true
EndWhile
Statement
sequence
Example - 12
• Inputs 5 numbers and outputs the sum and
average of them.
count = 1
sum = 0
WHILE count <= 5 Do
INPUT num
sum = sum + num
count = count + 1
END WHILE
average = sum / 5
DISPLAY sum, average
Exercise
• Draw the flow chart and write the
pseudo code for following scenario.
1. Calculate the sum of odd numbers
between 1 to 100
2. Calculate the sum of first ten
triangular numbers
3. Find the largest number among
three distinct integers
4. Input ten positive integer values and
Calculate the average.
5. Input 30 students name and ICT
mark, calculate the subject average
and print “Good Class” if average is
greater than or equal 50, otherwise
print “Bad Class”.