8.2 Examples
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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access