home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / out2.cpp < prev    next >
C/C++ Source or Header  |  1993-03-24  |  1KB  |  30 lines

  1. // C++ program uses the printf function for formatted output
  2.  
  3. #include <stdio.h> 
  4.  
  5. main()
  6. {
  7.   short    aShort     = 4;
  8.   int      anInt      = 67;
  9.   unsigned char aByte = 128;
  10.   char     aChar      = '@';
  11.   float    aSingle    = 355.0;
  12.   double   aDouble    = 1.130e+002;
  13.   // display sample expressions
  14.   printf("%3d %c %2d = %3d\n", 
  15.           aByte, '+', anInt, aByte + anInt);
  16.   
  17.   printf("Output uses the %%lf format\n");
  18.   printf("%6.4f / %6.4lf = %7.5lf\n", aSingle, aDouble,
  19.                                    aSingle / aDouble);
  20.   printf("Output uses the %%le format\n");
  21.   printf("%6.4e / %6.4le = %7.5le\n", aSingle, aDouble,
  22.                                    aSingle / aDouble);
  23.   printf("Output uses the %%lg format\n");
  24.   printf("%6.4g / %6.4lg = %7.5lg\n", aSingle, aDouble,
  25.                                    aSingle / aDouble);
  26.  
  27.   printf("The character in variable aChar is %c\n", aChar);
  28.   printf("The ASCII code of %c is %d\n", aChar, aChar);
  29.   return 0;
  30. }