0% found this document useful (0 votes)
5K views14 pages

Lesson 4

Here is the pseudocode: START • Declare Grade1, Grade2, Grade3, Grade4 as INTEGER • Declare Total, Average as INTEGER PRINT "Enter grade 1" INPUT Grade1 PRINT "Enter grade 2" INPUT Grade2 PRINT "Enter grade 3" INPUT Grade3 PRINT "Enter grade 4" INPUT Grade4 Total = Grade1 + Grade2 + Grade3 + Grade4 Average = Total / 4 PRINT "The average grade is", Average STOP

Uploaded by

api-297910907
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5K views14 pages

Lesson 4

Here is the pseudocode: START • Declare Grade1, Grade2, Grade3, Grade4 as INTEGER • Declare Total, Average as INTEGER PRINT "Enter grade 1" INPUT Grade1 PRINT "Enter grade 2" INPUT Grade2 PRINT "Enter grade 3" INPUT Grade3 PRINT "Enter grade 4" INPUT Grade4 Total = Grade1 + Grade2 + Grade3 + Grade4 Average = Total / 4 PRINT "The average grade is", Average STOP

Uploaded by

api-297910907
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Writing an Algorithm

Recapitulation
• Remember that an algorithm is a formal sequence of instructions of
how to solve a problem.
• In essence it is the recipe for solving a problem
Declaring variables
• In lesson 3 we learnt how to identify and name variables. Today we
will learn how to declare variables.
• When declaring a variable you give a suitable name and identify the
data type
What is a datatype?
• This is simply saying what type of data will your variable (container)
hold.
• Just as how you have a bag (container) to hold books, a wallet
(container) to store money and cards, a bottle (container) to store
water.
• There are 4 basic data types in algorithm.
Datatypes

Textual Numerical
• Character: This is used to hold a • Integer: This is used when the
single character for example a desire is to store a whole
letter or symbol. number for example number of
students in class.
• String: This is used to hold a
group of characters for example • Real: This is used to hold a
the name of a person decimal value for example price
of an item
Let’s declare some variables
• Write an algorithm that accepts the price and quantity of an item and
print the total price.

• Declare price as REAL


• Declare Quantity as INTEGER
• Declare Total Price as REAL
Activity 1
Identify and declare the variables in the problem statement below:
• Write an algorithm that accepts 4 grades and print the average grade.
Types of Algorithm
• An algorithm may be represented as a pseudocode, flowchart or
narrative.
Pseudocode
• This is a detailed yet readable description of what a computer
program or algorithm must do, expressed in a formally-styled natural
language rather than in a programming language.
Let’s Write a pseudocode
1) All algorithms will begin with the keyword START and end with STOP.
• Therefore go ahead and write :
START

Leave space to enter the Recipe

STOP
Cont’d writing pseudocode
• Take all the instructions that are under the P column in your defining
diagram and insert between START and STOP.
START
PRINT “Enter the quantity”
INPUT quantity
PRINT “Enter the price”
INPUT price
Total_Price=Price*Quantity
PRINT “The total price is”, Total_Price
STOP
Cont’d writing pseudocode
• Declare the variables immediately under the keyword START
START
• Declare price as REAL
• Declare Quantity as INTEGER
• Declare Total Price as REAL

PRINT “Enter the quantity”


INPUT quantity
PRINT “Enter the price”
INPUT price
Total_Price=Price*Quantity
PRINT “The total price is”, Total_Price
STOP
Now move to the NEXT Page
Activity 2
Write a pseudocode for the following problem statement:

• Write an algorithm that accepts 4 grades and print the average grade.

You might also like