Pseudo Code
Pseudo Code
Pseudo Code
com
PSEUDOCODE
Agenda
Intro to Pseudocode
Pseudocode vs Flowchart
Technique – Write pseudocode
Examples
What’s Pseudocode ?
Artificial and Informal language
Helps programmers to plan an algorithm
Similar to everyday English
Not an actual programming language
E.g : Pseudocode
Read A, B
Calculate C = A*B
Display C
Stop
Technique
Do not write Start in every pseudocode
Parallelogram – Read / Get OR Display /
Print
Rectangle – Specify the actions
◦ E.g:
Calculate A = B + C OR A equals to B plus C
Average = total / count
Final price equals price of item plus sales tax
Diamond – [Next »]
Technique (..Cont.)
Diamond
◦ Selection – IF , IF / ELSE and IF / ELSE IF
IF A is less than B
BIG = B
SMALL = A
ELSE
BIG = A
SMALL = B
◦ Repetition – WHILE / DO/WHILE / FOR [Next
example]
Comparative Between Flowchart vs
Pseudocode
Flowchart
◦ A graphical way of writing pseudocode
◦ Rounded rectangle – terminal
◦ Parallelogram – input / output
◦ Rectangle – actions
◦ Diamonds – decision / conditional
◦ Circles – connector
E.g : Flowchart
Start Terminal.
Start Program start
here
Read A Input.
Read B Enter values for
A and B
Calculate Resut
C=A*B Process
Display the
Result C Output
Stop Terminal
Stop Program end
here
Comparative Between Flowchart vs
Pseudocode (..Cont.)
Pseudocode
◦ No syntax rule – Independent from any
programming language
◦ Write in an ordinary language
◦ Uses a structure resembling computer
structure
◦ No connector between pages
E.g : Pseudocode
Read A, B
Calculate C = A*B
Display C
Stop
E.g : Pseudocode
Read A, B – Input
Calculate C = A*B - Action
Display C - Output
Stop - Terminal
Example 2 (Selection)
Read A, B
IF A is less than B
BIG = B
SMALL = A
ELSE
BIG = A
SMALL = B
Write / Display BIG, SMALL
Stop
Example 2 (Selection)
Read A, B - Input
IF A is less than B - Selection
BIG = B - Action
SMALL = A - Action
ELSE - Selection
BIG = A - Action
SMALL = B - Action
Write / Display BIG, SMALL - Output
Stop - Terminal
Example 3 (Repetition)
Set count to zero
Set total to zero
Read number