Develop the Algorithm
Using the notion of an algorithm and the concept of a variable, we develop the following algorithm for calculating the area of a square, given one side:
Algorithm for calculating area of square, given one side
(1) Ask the user for the length of a side
(2) Store the value in the box s
(3) Calculate the area of the square (s times s)
(4) Store the area in the box a
(5) Print the value in box a, appropriately labelled
(6) Stop
When an algorithm is developed, it must be checked to make sure that it is doing its intended job correctly. We can test an algorithm by ‘playing computer,' that is, we execute the instructions by hand, using appropriate data values. This process is called dry running or desk checking the algorithm. It is used to pinpoint any errors in logic before the computer program is actually written. We should never start to write programming code unless we are confident that the algorithm is correct. Here, the algorithm is fairly simple, so it is easy to check that it is indeed correct.