0% found this document useful (0 votes)
120 views49 pages

2.1.2 Pseudo Code

Pseudo code is a way to represent algorithms using a natural language-like syntax. It uses basic programming constructs like sequence, selection, and iteration to represent the steps of an algorithm without being tied to a specific programming language. Pseudo code uses commands like INPUT, OUTPUT, and arithmetic operators to represent input, output, and mathematical operations. It also allows for data structures like arrays and constants to be declared and used in algorithms. Pseudo code aims to clearly convey the overall logic of an algorithm independently of programming language details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views49 pages

2.1.2 Pseudo Code

Pseudo code is a way to represent algorithms using a natural language-like syntax. It uses basic programming constructs like sequence, selection, and iteration to represent the steps of an algorithm without being tied to a specific programming language. Pseudo code uses commands like INPUT, OUTPUT, and arithmetic operators to represent input, output, and mathematical operations. It also allows for data structures like arrays and constants to be declared and used in algorithms. Pseudo code aims to clearly convey the overall logic of an algorithm independently of programming language details.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 49

2.1.

2 Pseudo code

Introduction to Algorithm
An algorithm is a sequence of steps for solving a problem.
In general, an 'algorithm' is the name given to a defined set of steps used to
complete a
task.
For instance you could define an algorithm to make a cup of tea. You start by
filling the
kettle, and then place a tea bag in the cup and so on.
In computer terms, an algorithm describes the set of steps needed to carry out a
software task. This mini-web takes you through the topic of algorithm
The concept of a program
A program is a sequence of instructions or programming language statements
written to
make a computer perform certain tasks.
Well-structured programs require a programming language to support the
following
program constructs:
➢ sequence
➢ selection
➢ iteration

A computer’s processor can only run a computer program in the form of a file of machine
code, which is a sequence of binary codes representing instructions for the
processor.
The instruction set for a family of processors is the machine language in which
machine
code is written for that family of processors.
When machine code runs, the processor repeatedly:
➢ Fetches an instruction from internal memory
➢ Decodes the instruction
➢ Executes the instruction.
Constant:
Constant is memory location where a value can be stored but the stored value
remaining
same during execution.
It is good practice to use constants if this makes the pseudo code more readable,
as an
identifier is more meaningful in many cases than a literal. It also makes the
pseudo code
easier to update if the value of the constant changes.
Constant declaration
Constants are normally declared at the beginning of a piece of pseudo code
(unless it is
desirable to restrict the scope of the constant).
Constants are declared by stating the identifier and the literal value in the
following
format:

Only literals can be used as the value of a constant. A variable, another constant
or an
expression must never be used.

Input and output


Values are input using the INPUT command as follows:
INPUT <identifier>
The identifier should be a variable (that may be an individual element of a data
Structure such as an array, or a custom data type).
Values are output using the OUTPUT command as follows:
OUTPUT <value(s)>
Several values, separated by commas, can be output using the same command.
Example – INPUT and OUTPUT statements
INPUT Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"
Note that the syllabus for IGCSE (0478) gives READ and PRINT as examples for
INPUT
And OUTPUT, respectively.
Arithmetic operations
Standard arithmetic operator symbols are used:
• + Addition
• - Subtraction
• * Multiplication
• / Division
Care should be taken with the division operation: the resulting value should be of
data
type REAL, even if the operands are integers.
The integer division operators MOD and DIV can be used. However, their use
should be
explained explicitly and not assumed.
Multiplication and division have higher precedence over addition and subtraction
(this is
the normal mathematical convention). However, it is good practice to make the
order of
operations in complex expressions explicit by using parentheses.
Logic operators
The only logic operators (also called relational operators) used are AND, OR and
NOT.
The operands and results of these operations are always of data type
BOOLEAN.
In complex expressions it is advisable to use parentheses to make the order
Of operations explicit.

ARRAYS
Declaring arrays
Arrays are considered to be fixed-length structures of elements of identical data
type,
accessible by consecutive index (subscript) numbers. It is good practice to
explicitly state
what the lower bound of the array (i.e. the index of the first element) is because
this
defaults to either 0 or 1 in different systems. Generally, a lower bound of 1 will be
used.
Square brackets are used to indicate the array indices.
One- and two-dimensional arrays are declared as follows (where l, l1, l2 are
lower
bounds and u, u1, u2 are upper bounds):
Locating errors in questions

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy