Developing a
Pseudocode Algorithm
Presented by
Rev. Chester Dave Allman JP.
How do we create an algorithm?
● Creating an algorithm means developing steps for arriving at
a correct solution to a problem. For example, in baking a cake
one must know the steps involve to accomplish this task.
Attention must be paid to the sequence of operations in order
to arrive at a well baked cake. If the steps are not followed we
know what the result will be.
What is an algorithm?
An Algorithm is a step by step process in solving a
problem.
There are two main types of algorithm:-
✔ Pseudocode
✔ Flowcharts
● A pseudocode is an english-like
statement used to solve a
problem. The word pseudo
Pseudocode means FALSE
and
● A flow chart is a pictorial
Flow Chart representation of a pseudocode.
It uses symbols to solve a
problem.
● Three statements are
used mainly to solve
Statements used problems:-
in Problem ○ Input Statement
○ Output Statement
Solving ○ Assignment or
Process Statement
● An input ● Each
Input statement
statement is
Statement used to enter uses a
a variable KEYWORD
into an or a
algorithm or COMMAND.
a program.
Input Statement
● The KEYWORD or COMMAND for Input comprises of the
following:-
○ READ
○ INPUT
○ GET
○ ACCEPT
● Syntax refers to
INPUT Syntax the rules or
protocols
governing a
keyword or
command. Simply
READ (Variable(s)) put, how the
language must be
written for the
computer to
understand.
Variable
● A variable is a data item whose value is continually
changing. Simply put, a variable is a storage location.
For e.g Name, Number, Address etc.
● Anything that can store a value is a variable
● A variable can only store one item at a time.
Types of Variable
● There are two types of variables:-
○ A numeric variable
○ A character variable
● A numeric variable stores numbers. For e.g
Number, Age, Average, Price, Quantity etc.
Character Variable
● A Character variable stores
alphabetic characters. For e.g
Name, Address, Hair colour,
Complexion etc.
Example 1
● Write an instruction to enter a
name. Now the instruction did
not say enter PETER or
MICHELLE. It suggest that you
must use a storage location
called name to enter any name of
your choice.
Solution 1
● READ Name
Practice ● Write an instruction to input two
numbers?
Questions
● Write an instruction to enter a
name, address and telephone
number of a student?
● Write an instruction to input
three ages of your friend?
Naming ● There are rules governing the
naming of variables:-
Variables ○ They cannot begin with a
number.
○ They cannot carry spaces in
the naming.
● For example 5number is an illegal
Naming variable name because it begins with a
Variables number.
● Also N a me is an illegal variable name
because there are spaces in between the
letters
● The easiest way to name is to use
abbreviations we call ACRONYMS.
Examples of ● Write an instruction to enter
Naming name of student. A good
example of naming this
Variables
variable would be NOS.
● A variable name does
not have to be an actual
english word.
● Output is ❑ Keywords or
Output
used to give Commands
Statement the result of ● Write
what was ● Print
inputted or ● Display
processed. ● Output
Syntax
● Write (Variable(s))
Practice Questions
1. Write an instruction to accept the name of a student, grades
he/she receives in a test and the worth of the test. Output
the above information.
2. Write an instruction to input the name of a horse, the
position it came in a race and the prize money received.
Print the name of the horse and the prize money received.
● The assignment or
Assignment/ process statement is
Process used to do calculations
Statement while solving problems.
SYNTAX
● The syntax for an assignment statement is
usually a formula:-
Lv Rv
Syntax Explained ● The formula
simply explains
that the right
value is stored
in the left.
Process Statement
Examples
● A B This means B is stored
in A.
● A B+C This means B+C is
stored in A
Assignment Statement
Practice Question
● Interchange Glass A
containing Milk with
Glass B containing
Orange Juice.
Practice Question explained
● In order for the interchanging to take
place an extra glass must be brought in.
● So we now have Glass A, B & C
Practice Question
Explained
● So the following steps will make the
interchange possible:-
● C A This means A is now empty
● A B This means B is now empty
● B C This means C is now empty
The IPO Chart
● The Input, Processing and Output chart is used to analyse
the problem being solved. We try to ascertain:-
○ What is to be entered? (Input)
○ What are we calculating? (Processing)
○ What are we printing? (Output)
Practice Question
● Write an algorithm to ask
the user input two numbers.
Calculate and print the sum
of the two numbers.
IPO Chart Format
Input Processing Output
num1 Sum Sum
num2 num1+num2
Solution to practice
question 1
Start
Read num1, num2
Sum ← num1 + num2
Write Sum
Stop
Practice Question 2
● Write an algorithm to prompt
the user to input the number of
days in a month. Calculate and
print the number of hours in the
month.
IPO Chart Format
Input Processing Output
dim hrs dim*24 hrs
Solution to practice
question 2
Start
Read dim
hrs ← dim * 24
Write hrs
Stop
Practice Question 3
● Write an algorithm to input the name of a
student, the marks he/she received in a
test and the worth of the test. Calculate the
percentage mark the student received.
Print the name of the student and the
marks received.
IPO Chart Format
Input Processing Output
Nos, mks, wot pm nos
mks/wot * 100 pm
Solution to practice
question 2
Start
Read nos, mks, wot
pm ← mks/wot * 100
Write nos, pm
Stop
Prompt ● A prompt statement is used to tell the
Statement user what he or she is to do. It must be
a standard english statement.
● A prompt statement is an output
statement so it begins with an
OUTPUT COMMAND. It usually
begin with the word ENTER.
Prompt Statement - Syntax
● WRITE(“Statement”)
Prompt Statement -
Example 1
● Write an algorithm which prompts the
user to input two numbers. Calculate
and print the sum of the two numbers
Prompt Statement -
Solution 1
Start
Write “Please enter two numbers”
Read num1, num2
Sum ← num1 + num2
Write Sum
Stop
Prompt Statement -
Example 2
● Write an algorithm which prompts the user to input
the name of a student, the marks he or she received
in a test and the worth of the test. Calculate the
percentage mark the student received. Print the name
of the student and the percentage mark received.
Prompt Statement -
Solution 2
Start
Write “Please enter name of student, marks
received and worth of test”
Read nos, mks, wot
Pm ← mks / wot * 100
Write nos, pm
Stop
● When we label the
output we are
describing the
VARIABLE.
Labelling the
VARIABLE
● Simply put we are
telling what the
VARIABLE is.
Labelling the Variable -
Syntax
● Write (String), Variable
● Please note we place a string in
quotation marks (“string”)
Labelling the Variable -
Example 1
● Write an algorithm which prompts the
user to input two numbers. Calculate
and print the sum of the two numbers
using suitable labels.
Labelling the Variable -
Solution 1
Start
Write “Please enter two numbers”
Read num1, num2
Sum ← num1 + num2
Write “Sum ”, Sum
Stop
Labelling the Variable -
Example 2
Write an algorithm which prompts the user to input the
name of a student, the marks he or she received in a test
and the worth of the test. Calculate the percentage mark
the student received. Print the name of the student and the
percentage mark received using suitable labels.
Labelling the Variable -
Solution 2
Start
Write “Please enter name of student, marks received
and worth of test”
Read nos, mks, wot
Pm ← mks /wot * 100
Write “Name of Student ”, nos
Write “Percentage mark ”, pm
Stop
Practice question 1
Write an algorithm which prompts the user to input the name of a
horse, the position it came in a race and the prize money received.
Calculate the amount paid to trainer which is 10% of the prize
money. Output the name of the horse, position it came in the race
and the amount paid to trainer using suitable labels.
Solution to practice -
Question 1
Start
Write “Enter name of horse, position it came in a race and prize money received”
Read noh, pir, pmr
Apt ← pmr * 0.1
Write “Name of horse”, noh
Write “Position it came”, pir
Write “Amount paid to trainer”, Apt
Stop
Practice question 2
Write a structured algorithm that prompts the user
to input the length and width of a rectangle.
Calculate and print the area and the perimeter of the
rectangle using suitable labels.
Solution to practice
question 2
Start
Declare lor,wor,aor.por as real
Write “Enter name length and width of a rectangle”
Read lor, wor
Aor ← lor * wor
Por ← 2*(lor +wor)
Write “Area ”, Aor
Write “Perimeter ”, Por
Practice Question 3
Fees are charged to attend a cinema as follows:
Balcony $1500
House $1000
Write an algorithm which prompts the user to read the number of
persons sitting in the balcony and the number of persons sitting in the
house. Calculate and print the total revenue received using suitable
labels.
Solution to practice
question 3
Start
Declare pib,pih as integer
Declare Trev as real
Write “Enter number of persons sitting in both balcony and house”
Read pib, pih
Trev ← pib * 1500 + pih * 1000
Solution to practice
question 3 –Cont’d
Write “Total revenue”, Trev
Stop
Declaring Variables
● Declaring a variable gives the
name and a data type of the
variable being used.
Data types
● There are five different types of data used in problem solving:
○ Integer - positive and negative whole numbers
○ Real - fractional quantities or decimal numbers
○ String - collection of characters
○ Character - single letter or symbol
○ Boolean - Data type that has one of two values
Syntax for declaring Declare (Variable(s)) AS (Data type)
variables
Write an algorithm which prompts the
user to input name, address and telephone
number of a student.
Example of
Declaration Declare nos, addr, tele as String
Practice question 4
● Write a structured algorithm to ask the user to input three
numbers. Calculate and print the sum, product and average
using suitable labels
Solution to practice
question 4
Start
Declare num1, num2, num3, Sum, Pro as integer
Declare Avg as real
Write “Enter number three numbers”
Read num1, num2, num3
Sum ← num1 + num2 + num3
Pro ← num1 * num2 * num3
Avg ← Sum/3
Solution to practice
question 4
Write “Sum is”, Sum
Write “Product is”, Pro
Write “Average is”, Avg
Stop