0% found this document useful (0 votes)
89 views3 pages

Pseudocode Notes

Pseudocode is an informal way to represent an algorithm using structured English text, numbers and symbols. It describes the steps of a program without details of syntax. Examples show pseudocode for calculating the area of a square and adding three numbers. Keywords like INPUT, OUTPUT, PROCESSING are often used to indicate common operations in pseudocode.

Uploaded by

Brandon Williams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views3 pages

Pseudocode Notes

Pseudocode is an informal way to represent an algorithm using structured English text, numbers and symbols. It describes the steps of a program without details of syntax. Examples show pseudocode for calculating the area of a square and adding three numbers. Keywords like INPUT, OUTPUT, PROCESSING are often used to indicate common operations in pseudocode.

Uploaded by

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

 Pseudocode

o Is an informal program description of a program. It contains what is called syntax.


o It summarizes a program’s steps or flow but excludes underlying details.
o Pseudocode is a way of representing an algorithm using structured English text,
numbers and special characters.
o Syntax refers to the rules of any given programming language.

 Examples of simple pseudocode.


o Develop an algorithm in Pseudocode that will accept the values of the side of a square
and display its area where the formula is, area = side x side.

METHOD 1 METHOD 2
Start Start
write ‘Enter sides of square’ Write “Enter sides of square”
Read side Read side
Area = side x side Set A SIDE X SIDE
Print “The area is’, area. Write “The area is’,A
Stop Stop.

Method # 2 contain terms such as START, WRITE, SET and STOP. The write statement represents PRINT.
Start and Stop is the beginning and ending of the algorithm. The ARROW is similar to the equal sign, it is
stating that whatever is calculated will be stored in a variable. The SET statement stores the result of the
process or simply to initialize a variable.

 Another example of pseudocode.


o Add 3 numbers and output the result.
 Input num1
Input num2
Input num3
Sum = num1 + num2 + num3
Print sum.

Note: More examples of Pseudocode will be done in class.

*** KEYWORDS
There are several keywords that are often used to indicate common input, output and processing
operations in pseudocode.
 Input - READ, OBTAIN, GET, WRITE, PRINT
 Output – PRINT, DISPLAY, SHOW, WRITE
 Processing – COMPUTE, CALCULATE, DETERMINE
 Initialize – SET, INIT
 Add one – INCREMENT, BUMP

Consider the following problem statement.


Write a program to request the user to enter the name of an item and its price. The program should
calculate a 25% discount and print the item name and the new price.

Algorithm Pseudocode Algorithm

Start Start
For x 1 to 5 itemName
Enter item name itemPrice, discount, newPrice
Read item name x
Enter item price
Read item price set newPrice := 0;
Calculate discount set discount :=0;
Discount = Item price * 0.25
Calculate new price begin
Item price – discount For x := 1 to 5 do
Print item name write(enter item name)
Print new price read(itemName)
Stop. write(enter itemPrice)
read(itemPrice)

discount := itemPrice * 0.25


newPrice := itemPrice – discount

write(Item name)
write(New price of item)
end

Stop.
In the above example, the ALGORITHM on the left was written using everyday English language. It had nothing to do
with any programming language. It simple states the STEP to be followed to solve the problem statement. In the
PSEUDOCODE ALGORITHM, you would notice that the language is a bit different. Consider the following NEW thing in
the Pseudocode algorithm that the normal algorithm (on the left) does not have.
 The variables to be used in the program has been identified, no need to state the data type here, that will be
applicable only when you are writing the actual programming code.
 Some of the variables have been initialized. Usually the values that the user will enter (itemPrice) are NOT
initialized, ONLY the variables whose value is unknown at the start of the program or variables that have to be
calculated are initialized (newPrice, discount).
 Input/output statements are now clearly stated, however, you do not need to include the syntax (open/close
quotes, semicolon, colon etc) at this point, that is for the actual program code.
Eg
write(enter item name)
read(itemName)

 *** Some of the words such as WRITE/READ can be replaced with words from the paragraph in the previous
page that speaks about KEYWORDS

 Take note how the loop is to be stated in the PSEUDOCODE ALGORITHM. If conditions (if-then-else) are needed,
just incorporate it wherever it may be needed.

You might also like