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:

img

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:

img

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:

img

The required flowchart is shown in Figure 8.12.

Get Using LEDs, LCDs and GLCDs in Microcontroller Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.