You are on page 1of 4

Chapter 3

Algorithm and Coding

 There are 3 steps must be followed when writing a computer program:


1. Analyze
2. Writing the algorithm
3. Transform algorithm to computer language

Q) What is Algorithm?

Algorithm describes a series of instructions to solve a specific problem

 There are some rules must be followed when writing an algorithm:


1. Algorithm instructions begins with the word Start and finishes with the word End
2. Each instruction must be written in a sperate line
3. Most of the algorithms includes a dialogue between the computer and the user

2 important commands will help a lot while creating an algorithm

1. The command Read allows the user to put information from the keyboard
2. The command Write displays a message on the screen

Ex:

1. Variable a
2. Start
3. Write “Enter a number:”
4. Read a
5. Write “Its square is”, a*a
6. End

Explanation
Exercise

Q) Write an algorithm that will ask the user to input the age and display the user’s age

1. Variable age
2. start
3. Write “enter your age”
4. Read age
5. Write “your age is:”, + age (the + sign used to create space between the strings)
6. End

Q) write the algorithm which enables the user to type the length and the width of a rectangle and then
display its parameter

1. Variable L, W
2. Start
3. Write “enter Length”
4. Read L
5. Write “enter Width”
6. Read W
7. Parameter = L * W
8. Write “parameter is:” + parameter
9. End

Writing a program:
Note to remember:

Conditions:

If instruction

1. Variable a, b
2. Start
3. Write “enter a number”
4. Read a
5. Write “enter a number”
6. Read b
7. If a > b then
8. Write “a is bigger than b”
9. Else
10. Write “b is bigger than a”
11. Endif
12. End
Code:

Displaying 2 variables are very easy, for ex: write a code that will allow you to display your name and
your age together

You might also like