Problem Solving and
Program Design
Algorithms(Pseudocode)
OBJECTIVES
1. State the purpose of a pseudocode
2. State the keywords used for input statements, output
statements and assignment statements
3. Identify the parts of a Pseudocode algorithm.
Research the following
a. State the purpose of a pseudocode
b. State the keywords used for input statements, output statements
and assignment statements
c. Identify the parts of a Pseudocode algorithm.
d. Represent algorithms in the form of pseudocode
WHAT IS A PSEUDOCODE?
▪ A language consisting of English-like statements used to define
algorithm.
▪ A pseudocode is not a programming code, but uses English-type
words and phrases that are clear enough to be easily converted
into a programming code.
▪ Pseudocode can be developed from an IPO Chart to specify what
data is input and processed into information.
▪ One of three (3) ways to represent an algorithm.
Student’s response: Parts of
Pseudocode
▪ Algorithm header:
▪ Name
▪ author
▪ date
▪ description
▪ Declaration:
▪ Start
– Body
▪ Stop
Pseudocode: Product_of_three_numbers} Algorithm
Author/Developer: Ms Miller header
Date: December 2020 Documentatio
n
This algorithm find the average of 3 numbers Pseudocode
Description
Declare num1, num2,num3. product as integer Variable Declaration
Start
Print “Please enter three numbers”
Read num1, num2, num3 Input Statement
Product num1 * num2* num3 Assignment
Statement
Print “The product is: ” , Product Output /prompt
Statement
Stop Termination.
PSEUDOCODE:STATEMENTS
Read num1 Input
Statement
Read num2
sum num1 + num2 Assignment
Statement
Print “The sum of the numbers is”, sum
Output/prompt
Statement
PSEUDOCODE:STATEMENTS & KEYWORDS
▪ A statement is a description of the processing that can be
included in an action or condition.
▪ Instruction within the statements are called keywords.
▪ Examples of keywords are INPUT, READ, OUTPUT, DISPLAY,
PRINT or WRITE.
▪ In the development of a Pseudocode, there are three types of
Statements to consider:
1. Input Statement
2. Assignment Statements
3. Output Statements
STATEMENTS:INPUT STATEMENT
▪ The input statement provides the data required for processing or
calculation by the program.
▪ This is the way in which it will be written: Read variable_name
▪ Example: If you were required to read two numbers, find the sum
of the numbers and output the sum of the numbers. The input
statement would be:
Read num1
Read num2
Read two numbers, find the sum of the
numbers and output the sum of the numbers
IPO CHART: INPUT PSUEDOCODE: INPUT
INPUT
Read num1
Accept three
numbers
NUM1 Read num2
NUM2
Or
Accept NUM1,NUM2
STATEMENTS:ASSIGNMENT STATEMENT
▪ The assignment statements expresses the
calculation/processing of the data entered/provided.
▪ This is the way in which it will be written: variable_name = expression
▪ An assignment statement may involve an arithmetic
operation such as: sum num1 + num2
▪ While some assignment statements just involve assigning
values to variables, such as: Count 1
Highest_Price
0
Read two numbers, find the sum of the
numbers and output the sum of the numbers
PSUEDOCODE:
IPO CHART: Processing
Assignment Statement
PROCESSING
sum
1. Accept num1 + num2
NUM1,NUM2
2.Calculate total
TOTAL NUM1
+NUM2+NUM3
3. Print TOTAL
ARITHMETIC OPERATORS
ARITHMETIC OPERATORS EXAMPLES
Addition ( +) TotalPay= BasicPay+Bonus
Subtraction ( - ) NetPay=TotalPay-Tax
Multiplication ( * ) Days=Weeks*7
Division ( / ) Days=Hours/24
DIV- The operator DIV gives the result of integer Result =20 DIV 8
division, but not the remainder.
The variable “Result” would hold the value 2.
MOD-The operator MOD gives the remainder. Remainder= 20 MOD 8
The variable “Remainder” would hold
the value 4.
STATEMENTS:OUTPUT STATEMENT
▪ These statements provide/display the result of the calculation/processing of
the input given. They are also known as prompting statements.
▪ This is the way in which it will be written:
Print “statement”, variable_name Or Print variable_name
▪ For example, if you were required to read two numbers, find the sum
of the numbers and output the sum of the numbers. The output
statement would be:
Print “The sum of the numbers is”, sum
or
Print sum
Read two numbers, find the sum of the
numbers and output the sum of the numbers
PSUEDOCODE: Output
IPO CHART: Output
Statement
OUTPUT
Print “The sum of the numbers
is”, sum
Print TOTAL
Create an algorithm
which calculates the
sum of 3 numbers
Problem Solving and
Program Design
Algorithms(Pseudocode with IF construct)
OBJECTIVES
General objective(s):
▪ Understand when and how to include IF
statement within a pseudocode algorithm.
Specific objectives /learning outcomes:
– Define control structures
– State the three types of control structures
– Represent algorithms utilizing IF statements
RECAP
▪ What are Control Statements?
– These statements are used to control the amount of time a statement or
sequence of statements is carried out based on some condition.
▪ There are three main types of control structures that are
used in designing programs:
Sequence
Selection
Repetition
CONTROL STATEMENTS
▪ Sequence
– This is the structure that allows statements to be executed in the
order in which they are written in your program. Each statement
will only be executed once by the computer.
▪ Selection
– This control structures allow for decisions to be made in a
program based on a condition. Examples of those constructs are
the IF-THEN statement and the IF-THEN-ELSE statement.
▪ Repetition
– This allows statements to be repeated a fix number of time until
some condition evaluates to be false.
Assignment
Read and make notes on the following Selection
statements:
▪ IF –THEN
▪ IF-THEN-ELSE
IF-THEN statements
The IF-Then Statement suggest that one or more statements will only
be considered based on a condition or the answer to the question
IF (the condition is true)
THEN (carry out one or more statement)
ENDIF
The keyword ENDIF is used to indicate the end of the IF-THEN
statement. Any statement below ENDIF In the pseudocode is therefore
part of the general pseudocode and not specific to the IF-THEN
statement.
IPO CHART
▪ Write a program to read a mark and determine if the
mark is greater than or equal to 80. If the condition is
true, output the statements “ Excellent”, “Please see
your teacher”.
INPUT PROCESSING OUTPUT
READ Mark READ Mark Print “Excellent”
Print “Please see
IF Mark>=80 Then your teacher”
Print “ Excellent”
Print “Please see your
teacher”
ENDIF