Professional Documents
Culture Documents
PROBLEM 1:
Write a solution to read three
numbers and calculate and print
the total.
Breaking down the problem
State the input
State what should be processed
What should be outputted
Solution
Input Processing Output
Get 3 numbers Total
3 numbers
Eg. NUM1 Add 3
NUM2 NUM 3 numbers
Print total
PROBLEM 2
Number of hours
Set price per hour Total
Read number of Cost
hours
Calculate total
cost
total
Print total Cost
Distinguish between variables and
constants
In processing data, values that are manipulated
need to be stored in a memory location. Because of
the large number of storage location in memory,
we need to have an identifier to label each
location.
variables
Start
Print ‘Please enter your name’ Body
Input name
Print ‘Welcome to the world of problem-solving’,name
Stop {Terminat
or}
Characteristics of an algorithm
Have a set number of steps
Are precise
Are unambiguous
Have instructions that pass the flow from
one process to the next
Eventually terminate.
Ways of representing an algorithm
Algorithms can be represented using
pseudocode or a flowchart.
Input
Num1, num2
Output
Sum
End
Develop an algorithm that
accept two numbers. The
algorithm should find the
product of the two numbers
and output the result.
BEGIN
INPUT
num1,num2
Product num1 *
num1
Output
Product
End
Develop and algorithm that accept the age of three
boys. The algorithm must compute the average and
print the result.
BEGIN
INPUT
age1,age2,age3
sum age1+age2+age3
Average sum/3
Output
average
End
question
Develop an algorithm to accept the length and width of
a football field. The algorithm should compute the area
and output the result.
BEGIN
Output
Please enter length
and width
Area Length *
Width
Output
‘the area
is’,area
End
Develop an algorithm to perform the following task
1. Set a tax rate to 10%
2. Read an item price
3. Compute the tax payable on the item
4. Output the price after tax is added.
BEGIN
TaxRate 10%
Input ItemPrice
TaxPayable ItemPrice*TaxRate
Output Aftertax
Price
End
Using Pseudocode to represent
algorithm
Representing Algorithm using Pseudocode
Way of documenting an
algorithm using text, numbers
and special symbols .
Input Data
Verbs/construct to use
INPUT OR READ
How to use it
INPUT name
READ name
Initialise a variable
Assign a new value to a variable
Verbs/construct to use
STORE
How to use it
STORE 0 TO age
STORE age +1to age
Output Data and information
Verbs/construct to use
OUTPUT, PRINT, OR WRITE
How to use it
OUTPUT ‘Please enter a number’
PRINT ‘End of processing’
OUTPUT Total
WRITE ‘The total is’,total
Make a decision
Verbs/construct to use Verbs/construct to use
END
Develop and algorithm that accept the
age of three boys. The algorithm must
compute the average and print the result.
Flowchart Pseudocode
BEGIN
Print ‘Enter three ages’
Input age1, age2, age3
Set Sum to
age1+age2+age3
Set Average to Sum/3
Print ‘The sum is: ‘,Sum
Print ‘The average is: ‘,
Average
Stop
Develop an algorithm to accept the length and width of
a football field. The algorithm should compute the area
and output the result.
Flowchart
Pseudocode
BEGIN
END
Develop an algorithm to perform the following task
1. Set a tax rate to 10%
2. Read an item price
3. Compute the tax payable on the item
4. Output the price after tax is added.
Using pseudocode
BEGIN
STORE 10% to taxrate
INPUT itemPrice
STORE itemprice * taxrate to Taxpayable
STORE itemprice + taxpayable to AfterTaxPrice
OUTPUT AfterTaxPrice
END
Selection
A selection is a construct is
used to evaluate a condition(ask
a question) and carry out one or
more actions based on the result
of the outcome. It is also called
decision construct.
INPUT Score
Score > 50
STOP
Using flow charts