home *** CD-ROM | disk | FTP | other *** search
- // C++ program uses the printf function for formatted output
-
- #include <stdio.h>
-
- main()
- {
- short aShort = 4;
- int anInt = 67;
- unsigned char aByte = 128;
- char aChar = '@';
- float aSingle = 355.0;
- double aDouble = 1.130e+002;
- // display sample expressions
- printf("%3d %c %2d = %3d\n",
- aByte, '+', anInt, aByte + anInt);
-
- printf("Output uses the %%lf format\n");
- printf("%6.4f / %6.4lf = %7.5lf\n", aSingle, aDouble,
- aSingle / aDouble);
- printf("Output uses the %%le format\n");
- printf("%6.4e / %6.4le = %7.5le\n", aSingle, aDouble,
- aSingle / aDouble);
- printf("Output uses the %%lg format\n");
- printf("%6.4g / %6.4lg = %7.5lg\n", aSingle, aDouble,
- aSingle / aDouble);
-
- printf("The character in variable aChar is %c\n", aChar);
- printf("The ASCII code of %c is %d\n", aChar, aChar);
- return 0;
- }