home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch9 / threedim.c < prev   
C/C++ Source or Header  |  2005-06-16  |  2KB  |  44 lines

  1. /*                    threedim.c
  2.  *
  3.  *   Synopsis  - Displays the contents of a three-dimensional 
  4.  *               array as a pair of two-dimensional arrays.
  5.  *
  6.  *   Objective - Illustrates declaration, initialization, and
  7.  *               element access in a three-dimensional array.
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12.  
  13. /* Constant Definitions */
  14. #define DIM1    2
  15. #define DIM2    3
  16. #define DIM3    4
  17.  
  18. int main( void )
  19. {
  20.                                                             /* Note 1 */
  21.      double three_d[DIM1][DIM2][DIM3] = {                   /* Note 2 */
  22.                                           {  { 0.0, 0.1, 0.2, 0.3 },
  23.                                              { 1.0, 1.1, 1.2, 1.3 },
  24.                                              { 2.0, 2.1, 2.2, 2.3 }
  25.                                           },
  26.                                           {  { 10.0, 10.1, 10.2, 10.3 },
  27.                                              { 11.0, 11.1, 11.2, 11.3 },
  28.                                              { 12.0, 12.1, 12.2, 12.3 }
  29.                                           }
  30.                                         };
  31.      int i, j, k;
  32.  
  33.      for ( i = 0; i < DIM1; i++ ) {
  34.           for ( j = 0; j < DIM2; j++ ) {
  35.                for ( k = 0; k < DIM3; k++ ) {               /* Note 3 */
  36.                     printf( "%5.1f\t", three_d[i][j][k] );
  37.                }
  38.                printf( "\n" );
  39.           }
  40.           printf( "\n\n" );
  41.      }
  42.      return 0;
  43. }
  44.