## Algorithm

There are some few words you come across when you start learning any programming languages.

An algorithm is a strictly defined finite sequence of well-defined instructions that provides the solution to a problem. In other words, an algorithm is a step-by-step procedure to solve a given problem. The term “finite” means that the algorithm should reach an end point and cannot run forever.

You can find algorithms everywhere in your real life, not just in progrogramming. For instance, the process for preparing a cup of milk can be expressed as an algorithm. Certain steps, in a certain order, must be followed in order to achieve your goal.

Here is the algorithm for making a cup of milk

- Put the powder milk in a cup.
- Fill the kettle with water.
- Boil the water in the kettle.
- Pour some of the boiled water into the cup.
- Add sugar to the cup.
- Stir the milk.
- Drink the milk.
However,if you are like me who does not drink milk, let us jot down the algorithm to add two numbers X and Y.

- declare a variable X.
- declare a variable Y.
- declare a variable Z.
- Z=X+Y.
You should not worry about the notation X, Y and Z.They are just alphabet used in discrete mathematics. In real live scenario, a finite value is store in the variable which is out of the scope of this session.

## The Three Main Stages Involved in Creating an Algorithm

Three main stages are involved in creating an algorithm: data input, data processing, and results output. The order is specific and cannot be changed. Consider a computer program that finds the average value of three numbers. First, the program must prompt the user to enter the numbers (data input). Next, the program calculates the average value of the numbers (data processing). Finally, the program displays the result on the computer’s screen (results output).

- Prompt the user to enter a number.
- Prompt the user to enter a second number.
- Prompt the user to enter a third number.
- Calculate the sum of the three numbers.
- Divide the sum by 3.
- Display the result on the screen.
From stept 1 to 3 represent data inputs

From step 4 to 5 represent data process

Step 6 represents data outputIn a nutshell, solving a programming problem is easy. The only tool you need is your thinking pattern to write the correct algorithm.