home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1988 / 06 / fpdemo.c < prev    next >
C/C++ Source or Header  |  1988-03-28  |  802b  |  28 lines

  1. /*  
  2.         fpdemo.c --- demonstrates use of printf to format
  3.                      pretty tables of floating point numbers
  4.         PC Magazine - Ray Duncan
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. main(int argc, char *argv[])
  11. {  
  12.    int i,j;                             /* some integer variables */
  13.    double f;                            /* floating point variable */
  14.  
  15.    printf("\n\nPrintf floating point demo\n\n\t");
  16.  
  17.    for(i=1; i<11; i++)                  /* print column numbers */
  18.       printf("%7d", i);
  19.  
  20.    for(i=1; i<21; i++)
  21.    {  printf("\n%2d\t", i);             /* print row numbers */
  22.       for(j=1; j<11; j++)
  23.       {  f=(double) j / (double) i;     /* type cast and divide */
  24.          printf("%7.3f", f);            /* display results */
  25.       }
  26.    }
  27. }
  28.