0% found this document useful (0 votes)
70 views

Algorithm Advanced Manual

The document discusses flow charts and pseudo codes. It defines key components of flow charts like symbols used to represent tasks, decisions, inputs/outputs etc. It also explains different types of logic used in algorithms - sequence, selection and iteration. Several examples of problems are provided and their solutions shown using flow charts and pseudo codes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Algorithm Advanced Manual

The document discusses flow charts and pseudo codes. It defines key components of flow charts like symbols used to represent tasks, decisions, inputs/outputs etc. It also explains different types of logic used in algorithms - sequence, selection and iteration. Several examples of problems are provided and their solutions shown using flow charts and pseudo codes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Flow Charts And

Pseudo Codes
Grade 12

GCE ( A/L )- ICT Teacher Training Program – 2011


• An algorithm is a complete step-by-
step procedure for solving a problem
or accomplishing a task
 Flowcharts
 Pseudo Codes
 It is a step by step Diagrammatic
representation of the program

 Each type of task is represented by a


symbol
Diagram Notation Representation
Oval Start / End of a Program

Parallelogram Input / Output of Data

Rectangle Processing Operation

Rhombus Decision Box


Diagram Notation Representation

Circle Connection

Flow Lines Direction of Flow

Rectangle Sub Process


Start Eg : Start

Inputs Input a , b

Calculations Sum = a + b

Outputs Output Sum

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

Find the sum and Input


Number1

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

IF-THEN-ELSE is a decision (selection) in


which a choice is made between two alternative
courses of action
True False
Condition?

Statement sequence 1 Statement sequence 2


• Input the length and width of a
quadrilateral and state whether it is a
square Start

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

Get Length, width

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

 A small circle is used to represent a connector


in a flowchart

 An alphabet or a number is written inside the


circle to identify the pairs of connectors to be
joined
A

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

• Find the sum total = 0

of 10 numbers No

Counter< 10
?
yes

Display total
Get Number

Stop
total = total+number

counter=counter+1
For
Start For

Control_variable = Start Value

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

Input m1, m2, m3, m4

average = ( m1 + m2 + m3 + m4 ) /4

IF Average < 50
false

true
Display
N
Display “Pass”
“Fail”

Stop
Example -8

• A company gives discounts for the


total bill paid by the customers. If
the Bill amount is above Rs. 5000/-, a
discount of 10 % is given. Otherwise
5% is given. Input the Bill amount
and calculate the discount amount.
Start

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

• A company pays a basic salary of


Rs. 8000/- to the salesmen. If a
salesman does sales of Rs. 50,000/-
or above, he is given a 25%
commission. Otherwise only 10%.
Input the sales done by a salesman and
calculate his salary for the month.
Start

Commission = 0, Tot_Salary = 0

Input Sales_Amount

false
IF
Sales_Amount
> = 50000
true
Commission = Sales_Amount * 0.25 Commission = Sales_Amount * 0.10

Tot_Salary = 8000 + Commission

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

• It is an abbreviated version of actual computer code


(that’s why it is called Pseudocode)

• Once pseudocode is created, it is simple to translate


into real programming code.
• Sequence
– Use set of instructions one after the
other
• Selection
– Use IF … THEN … ELSE
• Repetition
– Use WHILE, FOR, REPEAT…UNTILL
Sequence
START
Pseudocode;

statement 1
Statement 1
statement 2

statement 3
Statement 2

Statement 3

STOP
Example - 10

• Write a pseudo code that inputs two


numbers (a and b) and calculates the
sum of the numbers and output the
sum

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”.

You might also like