# What is an Algorithm ?

A sequence of steps or instructions to solve a particular problem. An algoritm has following properties:

### Finiteness

The number of steps involved in an Algorithm to solve a problem must be finite.

### Simplicity:

The steps involved in an algorithm must be simple, so that the output can be computed easily.

### Input:

To solve any problem, the algorithm must recieve some input

### Output:

The algorithm must produce at leat one output which is the solution to the problem.

### Correctness

The algorithm must perform the task it is designed to perform, for all input values.

### Generality

The procedure used in a specific algorithm should be applicable to all algorithms of same general form.

## Variables in Algorithm.

Variables are always used in Capital Letters. e.g num variable will be used as** NUM **in Algorithm.

## How to write some Operators in Algorithm ?

| This is used as Assignment operator in Algorithm. |

## Relational Operators in Algorithm.

| This is used as less than operator in Algorithm. |

| This is used as greater than operator in Algorithm. |

| This is used as less than or equal to operator in Algorithm. |

| This is used as greater than or equal to operator in Algorithm. |

| This is used as comparison operator in Algorithm. |

| This is used as not equal to operator in Algorithm. |

| These are used as logical operators in Algorithm. |

## Arithmetic operators.

**Arithmetic operators**are used as it is they are used in program.

## Increment and Decrement Operators in Algorithm.

Increment operators are used as e.g I = I + 1 where I is a variable.

Decrement operators are used as e.g I = I - 1 where I is a variable.

## How to assign value to a variable in Algorithm ?

Assigning value to a variable in Algorithm e.g NUM <- 10

or NUM := 10

## How to Print a string message in Algorithm ?

Write("Welcome to Compuhelp")

## How to Print a variable in Algorithm ?

Write(NUM)

## How to Print string message and variable in Algorithm ?

Write(“The value is”, NUM)

## How to take input in Algorithm ?

Read(NUM)

## How to use comments in algorithm ?

Single and Multiline comment. e.g [This is commented statement ] . Comments are used to make your Algorithm more descriptive and meaningful.

## Syntax to use if statement in Algorithm.

[Statements]

[End of If Structure]

## Syntax to use if else statement in Algorithm ?

[Statements]

Else

[Statements]

[End of If Else Structure]

## Syntax to use if else if statement in Algorithm ?

[Statements]

Else If condition then

[Statements]

[End of If Else If Structure]

## Syntax to use for loop in Algorithm ?

//Steps 3 to 5

[End of For Loop]

## Syntax to use while loop in Algorithm.

While condition

//Steps 3 to 5

[End of While Loop]

## Syntax of break and continue in Algorithm.

## Syntax to use Array in Algorithm.

## How to use Functions in Algorithm.

### Function with no argument and no return.

[Statements]

Return

### Function with argument and no return.

[Statements]

Return

### Function with no argument and with return.

[Statements]

Return NUM

### Function with argument and with return.

[Statements]

Return A

## Algorithm of adding two values stored in two variables and display the result using third variable.

Step 1. START

Step 2. NUM1 := 10, NUM2 := 20

Step 3. RES := NUM1 + NUM2

Step 4. Write(“The sum is “, RES)

Step 5. END