Yogeswaran

Posted on

# WAYS OF WRITING AN ALGORITHM

There are various ways of writing an algorithm. Today, I'm going to explain 3 ways of writing an algorithm.

### 1. English-Like Algorithm

An algorithm can be written in many ways. It can be written in simple English but this method also has some demerits. Natural language can be ambiguous and therefore lack the characteristic of being definite. Each step of an algorithm should be clear and shouldn't have more than one meaning. English language-like algorithms are not considered good for most of the tasks.

### 2. Flowchart

Flowcharts pictorially depict a process. They are easy to understand and are commonly used in the case of simple problems.

Flowchart Conventions

### 3. Pseudocode

The pseudocode has an advantage of being easily converted into any programming language. This way of writing algorithm is most acceptable and most widely used. In order to write a pseudocode, one must be familiar with the conventions of writing it.

{
statements
}

#### 5. Assignment statements indicates that the result of evaluation of the expression will be stored in the variable.

< variable > = < expression >

#### 16. This condition is an enhancement of the above 'if' statement. It can also handle the case where the condition isn't satisfied.

if< condition >then< statement1 >else< statement2 >

#### 17. switch case (C or C++)

case {
:< condition 1 >: < statement 1 >
.....
.....
.....
:< condition n >: < statement n >
:default: < statement n+1 >
}

#### 18. while loop

while< condition >do {
statements
}

#### 19. do-while loop

repeat
statements
until< condition >

#### 20. for loop

for variable = value1 to value2 {
statements
}

Print

#### 23. The name of the algorithm is < name > and the arguments are stored in the < parameter list >

Algorithm< name > (< parameter list >)

Note: Number 6 to Number 11 use relational operator, Number 12 to 14 uses logical operator, and Number 15 uses conditional operator.

Join My Telegram Community so you won't miss out any articles.