[go: up one dir, main page]

0% found this document useful (0 votes)
24 views12 pages

Pseudocode - L1, L2

The document discusses different ways to represent algorithms, including structured English, flowcharts, and pseudocode. It then provides examples of key elements of pseudocode, such as variables, constants, assignment, input/output, arithmetic operators, selection statements, and basic data types. Pseudocode uses a simple English-like syntax to describe the steps of an algorithm without being bound to the rules of a specific programming language.

Uploaded by

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

Pseudocode - L1, L2

The document discusses different ways to represent algorithms, including structured English, flowcharts, and pseudocode. It then provides examples of key elements of pseudocode, such as variables, constants, assignment, input/output, arithmetic operators, selection statements, and basic data types. Pseudocode uses a simple English-like syntax to describe the steps of an algorithm without being bound to the rules of a specific programming language.

Uploaded by

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

Flowcharts & Pseudocode

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.

CONSTANT Discount ← 0.1


3. Assignment
Assignment is the process of writing a value into a variable (a named memory location). For
e.g. Count ← 1 can be read as ‘Count is assigned the value 1.
4. Input
We indicate input by words such as INPUT, READ or ENTER, followed by the name of a
variable
to which we wish to assign the input value.

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:

Total ← Total + Number

(Add number to Total variable)


6. Counting
It is sometimes necessary to count how many times something happens.
To count up or increment by 1, we can use statements such as:

Count ← Count +1 (Increment Count by 1)

7. Operators
There are two types of operators:
i . Arithmetic Operators
ii. Logical and Relational operators

Arithmetic Operators
Logical and Relational Operators

8. Basic Data Types


The most used data types are:

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.

You might also like