Hardware Reference
In-Depth Information
Figure 7.5 Source code as it appears in the Borland C++ 4.5 editor
increased by 1 on each pass round the loop. Formatted output is achieved by
printing column headings before the loop is entered and including field-width
specifiers within the format string.
/* Name:
table.c
*/
/* Language: Borland C++ 4.5
*/
/* Output:
Table of decimal, hex. and ASCII characters */
/* Note:
Program runs in a DOS console window
*/
#include <stdio.h>
int byte;
int main()
{
printf("Decimal Hex. ASCII \n");
for (byte = 32; byte < 128; ++byte)
{
printf("%3d \t %2X \t %c \n", byte, byte, byte);
}
return 0;
}
The output produced by the program is shown in Figure 7.6.
Loops can also be nested to any required depth. The following Borland
C ++ 4.5 program provides a simple example based on the use of while rather
than for :
/* Name:
loop1.c
*/
/* Language: Borland C++ 4.5
*/
/* Output:
Table of decimal, hex. and ASCII characters */
/* Note:
Program runs in a DOS console window
*/
Search WWH ::




Custom Search