Pseudocode - L1, L2
Pseudocode - L1, L2
Algorithms
An algorithm is a sequence of steps done to perform some task.
• The essential aim of an algorithm is to get a specific output,
• An algorithm involves with several continuous steps,
• The output comes after the algorithm finished the whole process.
So basically, all algorithms perform logically while following the steps to get an output
for a given input.
Methods of Representing an Algorithm:
• Structured English
• Flowcharts
• Pseudocode
STRUCTURED ENGLISH:
Structured English provides a more formal way of documenting the stages of the algorithm.
Structured English is a subset of English language that consists of command statements used
to describe an algorithm.
FLOWCHARTS:
Flow chart is a graphical representation of a program.
Flowcharts use different symbols containing information about steps or a sequence of events.
YES
PSEUDOCODE:
Pseudocode is an outline of a program, written as a series of instruction using simple English
sentences.
Pseudocode uses keywords commonly found in high – level languages and mathematical
notation. It describes an algorithm ‘s steps like program statements, without being bound
by the strict rules of vocabulary and syntax of any particular language, together with
ordinary English.
1. Variable
Variable is memory location where a value can be stored.
DECLARE Marks : INTEGER
Marks ← 0
2. Constants
Just like variables, constants are "data holders". They can be used to store data that is needed
at runtime.
In contrast to variable, the content of a constant can't change at runtime, it has a constant value.
Before the program can be executed (or compiled) the value for a constant must be known.
INPUT Marks
READ Sname
5. Totaling
To keep a running total, we can use a variable such as Total or Sum to hold the running total
and assignment statements such as:
7. Operators
There are two types of operators:
i . Arithmetic Operators
ii. Logical and Relational operators
Arithmetic Operators
Logical and Relational Operators
Real
9. Selection /Conditional Statements
These statements are used to select alternative routes through an algorithm;
expressions often involve comparisons, which can operate on text strings as well as
numbers.
i) IF – THEN – ELSE – ENDIF
ii) CASE – OF – OTHERWISE - ENDCASE
i) IF – THEN – ELSE – ENDIF
For an IF condition the THEN path is followed if the condition is true and the ELSE path is
followed if the condition is false.
There may or may not be an ELSE path. The end of the statement is shown by ENDIF.
A condition can be set up in different ways:
Example 1:
IF ((Height > 1) OR (Weight > 20) OR (Age > 5)) AND (Age < 70)
THEN PRINT “You can ride“
ELSE PRINT “Too small, too young or too old”
ENDIF
Example 2:
Example 3:
Q.