You are on page 1of 16

Pseudocode

 Pseudocode is an intermediate notation


(between English and a programming
language) used to write algorithms.
 An algorithm can be written in pseudocode
using 6 basic computer operations.
Approved Notation for Pseudocode

Take note of the following rules for each of the items below.
Approved Notation for Pseudocode

The following symbols must be used.


Pseudocode

1. A computer can receive information.


Typical pseudocode instructions:
input NAME # very
common
input NUM1, NUM2
Pseudocode

2. A computer can output information.


Typical pseudocode instructions:

output NAME
output “Bob” # very common
output AGE
Pseudocode

3. A computer can perform arithmetic


operations.
Typical pseudocode instructions:

TOTAL = TOTAL + NUM


AVG = SUM/COUNT
AREA = PI * RADIUS ** 2
Pseudocode

4. A computer can assign a value to a piece of


data.
Typical pseudocode instructions:

COUNT = 0
TOTAL = PRICE + TAX
Pseudocode

5. A computer can compare 2 pieces of


information and select one of two actions.
Decision making pseudocode:

if NUM mod F = 0 then


SUM = NUM + 1
end if
Pseudocode

Decision making pseudocode:

if S = “Hello” then
output S
else
output “Goodbye”
end if
Pseudocode

Decision making pseudocode:


if NUM mod F = 0 then
SUM = NUM + 1
else if NUM > 50 then
SUM = SUM + 2
else
output NUM
end if
Pseudocode

6. A computer can repeat a group of actions.


Typical pseudocode instructions:

loop until SUM >= 50


input NUM
output NUM
SUM = SUM + 5
end loop
Pseudocode

More examples on pseudocode repetition:

loop while SUM <= 50


input NUM
output NUM
SUM = SUM + 1
end loop
Pseudocode

More examples on pseudocode repetition:

loop N from 0 to 999


input NUM
output NUM
SUM = SUM + NUM
end loop
CALCULATING AREA OF A CIRCLE

This algorithm will calculate the area of a circle given the radius.
Variables: AREA, RADIUS, PI
PI = 3.14159 //set value of pi accurate to 5 decimal places
BEGIN
input RADIUS
AREA = PI * RADIUS **2
output AREA
END
Notice: Input – Processing – Output (IPO Model)
Review Questions

1. What is pseudocode?
2. What are the approved notations for
conventions, variable names, assignment,
and output?
3. Name the standard mathematical operators
used in programming.
4. What is the pseudocode notation for
comparing information?
Questions Continued…

5. Using pseudocode notation, how do you


repeat a group of actions? Explain.

You might also like