Step-form
Some examples of developing an algorithm using step-form
For illustrating the step-form the following conventions are assumed:
Each algorithm will be logically enclosed by two statements START and STOP.
To accept data from the user, the INPUT or READ statements are to be used.
To display any user message or the content of a variable, a PRINT statement will be used.
Note:- that the message will be enclosed within quotes.
There are several steps in an algorithm. Each step results in an action. The steps are to be acted upon sequentially in the order they are arranged or directed.
For Example:
- Start
- Print “Hello world”
- Stop
Operators Used in Algorithm:
The arithmetic operators that will be used in the expressions are
(i) ‘←’ ….Assignment (the left-hand side of ‘←’ should always be a single variable)
Example:
The expression x ← 6 means that a value 6 is assigned to the variable x. In terms of memory storage, it means a value of 6 is stored at a location in memory that is allocated to the variable x.
(ii) ‘+’….. Addition
Example:
The expression z ← x + y means the value contained in variable x and the value contained in variable y is added and the resulting value obtained is assigned to the variable z.
(iii) ‘–’….. Subtraction
Example:
The expression z ← x – y means the value contained in variable y is subtracted from the value contained in variable x and the resulting value obtained is assigned to the variable z
(iv) ‘*’….. Multiplication
Example:
Consider the following expressions written in sequence:
x ← 5
y ← 6
z ← x * y
The result of the multiplication between x and y is 30. This value is therefore assigned to z.
(v) ‘/’….. Division
Example:
The following expressions written in sequence illustrates the meaning of the division operator :
x ← 10
y ← 6
Z ← x/y
In propositions, the commonly used relational operators will include
(i) ‘>’ ….. Greater than
Example:
The expression x > y means if the value contained in x is larger than that in y then the outcome of the expression is true, which will be taken as 1. Otherwise, if the outcome is false then it would be taken as 0.
(ii) ‘<=’ …..Less than or equal to
Example:
The expression x <= y implies that if the value held in x is either less than or equal to the value held in y then the outcome of the expression is true and so it will be taken as 1. But if the outcome of the relational expression is false then it is taken as 0.
(iii) ‘<’ …… Less than
Example:
Here the expression x < y implies that if the value held in x is less than that held in y then the relational expression is true, which is taken as 1, otherwise the expression is false and hence will be taken as 0.
(iv) ‘=’ …… Equality
Example:
The expression x = y means that if the value in x and that in y are the same then this relational expression is true and hence the outcome is 1 otherwise the outcome is false or 0.
(v) ‘>=’ …… Greater than or equal to
Example:
The expression x >= y implies that if the value in x is larger or equal to that in y then the outcome of the expression is true or 1, otherwise it is false or 0.
(vi) ‘!=’ …… Non- equality
Example:
The expression x != y means that if the value contained in x is not equal to the value contained in y then the outcome of the expression is true or 1, otherwise it is false or 0.
The most commonly used logical operators will be AND, OR, and NOT.
These operators are used to specify multiple test conditions forming a composite proposition.
(i)‘AND’…… Conjunction
The outcome of an expression is true or 1 when both the propositions AND-ed are true otherwise it is false or 0.
Example: Consider the expressions
x ← 2
y ← 1
x = 2 AND y = 0
In the above expression, the proposition ‘x = 2’ is true because the value in x is 2. Similarly, the proposition ‘y = 0’ is false as y holds 1 and therefore this proposition is false or 0. Thus, the above expression may be represented as ‘true’ AND ‘false’ the outcome for which is false or 0.
(ii) ‘OR’ …… Disjunction
The outcome of an expression is true or 1 when any one of the propositions OR-ed is true otherwise it is false or 0.
Example: Consider the expressions
x ← 2
y ← 1
x != 2 OR y = 0
Here, the proposition ‘x = 2’ is true since x holds 2 while the proposition ‘y = 0’ is untrue or false. Hence the third expression may be represented as ‘true’ OR ‘false’ the outcome for which is true or 1.
(iii) ‘NOT’ …… Negation
If the outcome of a proposition is ‘true’, it becomes ‘false’ when negated or NOT-ed.
Example: Consider the expression
x ← 2
NOT x = 2
The proposition ‘x = 2’ is ‘true’ as x contains the value 2. But the second expression negates this by the logical operator NOT which gives an outcome ‘false’.
Check Examples - CLICK HERE
0 Comments