Page 56 - Viva ICSE Computer Studies 8 : E-book
P. 56
Algorithm
An algorithm is a step-by-step instruction written in simple English language to perform a
particular task. The fi rst step in generating a computer program is to understand the problem
and put down the steps in a sequence to get the result. Let’s understand the concept of
algorithm by taking a real life situation.
Algorithm to prepare a cup of tea
Step 1: Take a cup of water in a pan and switch on the gas.
Step 2: Crush some ginger and put it in the pan.
Step 3: Add sugar and tea leaves into it. Let it boil for 3 minutes.
Step 4: Pour a cup of milk into it and boil it for about 2 minutes.
Step 5: Filter the tea in a cup, leaving the tea leaves behind and enjoy your cup of tea.
Advantages of an Algorithm
There are many advantages of writing algorithms. Some of them are as follows.
• Algorithms are easy to understand, implement and modify.
• Algorithms are independent of any computer language.
• Algorithms can be easily converted into fl owcharts and then into computer programs.
Rules for Writing Algorithms
There are certain rules that we need to follow while writing an algorithm.
Follow the given rules to write algorithms.
• Algorithm must begin with the word ‘Start’.
• Number the statements such as Step 1, Step 2 and so on.
• Write the statements clearly.
• Each statement must be written in a separate line.
• Each step should be clear and precise.
• Algorithm must end with the word ‘Stop’.
Example of an Algorithm
Example 1: Algorithm to add three numbers
Step 1: Start.
Step 2: Take three numbers A, B and C.
Step 3: Add the three numbers.
Step 4: Print the result.
Step 5: Stop.
Example 2: Find the smallest of two numbers.
Step 1: Start.
Step 2: Take two numbers X and Y.
44