Some examples are given in this section, to show how the PDL and flowcharts can be used in program development.
Example 8.1
It is required to a write a program to convert hexadecimal numbers ‘A’ to ‘F’ into decimal. Show the algorithm using a PDL and also draw the flowchart. Assume that the number to be converted is called HEX_NUM and the output number is called DEC_NUM.
Solution 8.1
The required PDL is:
The required flowchart is shown in Figure 8.10. Notice that it is much easier to write the PDL statements than drawing the flowchart shapes and writing text inside them.
Example 8.2
The PDL of part of a program is given as follows:
Show how this PDL can be implemented by drawing a flowchart.
Solution 8.2
The required flowchart is shown in Figure 8.11. Here again, notice how complicated the flowchart can be, even for a simple nested DO WHILE loop.
Example 8.3
It is required to write a program to calculate the sum of integer numbers between 1 and 100. Show the algorithm using a PDL and also draw the flowchart. Assume that the sum will be stored in a variable called SUM.
Solution 8.3
The required PDL is:
The required flowchart is shown in Figure 8.12.
Example 8.4
It is required to write a program to calculate the sum of all the even numbers between 1 and 10 inclusive. Show the algorithm using a PDL and also draw the flowchart. Assume that the sum will be stored in a variable called SUM.
Solution 8.4
The required PDL is:
The required flowchart is shown in Figure 8.13. Notice how complicated the flowchart can be for a very simple problem such as this.
18.225.95.60