home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch6 / switch.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  31 lines

  1. /*                     switch.c
  2.  *
  3.  *   Synopsis  - Displays a triangle of numbers.
  4.  *   Objective - To illustrate the syntax and flow of control
  5.  *               of the switch statement.
  6.  */
  7.  
  8. /* Include Files */
  9. #include <stdio.h>
  10.  
  11. int main( void )
  12. {
  13.      int test_value;
  14.  
  15.      printf( "Enter an integer between 0 and 9: " );
  16.      scanf( "%d", &test_value );
  17.      switch ( test_value ) {                             /* Note 1 */
  18.           case 9:    printf( "9 9 9 9 9 9 9 9 9\n" );    /* Note 2 */
  19.           case 8:    printf( " 8 8 8 8 8 8 8 8\n" );
  20.           case 7:    printf( "  7 7 7 7 7 7 7\n" );
  21.           case 6:    printf( "   6 6 6 6 6 6\n" );
  22.           case 5:    printf( "    5 5 5 5 5\n" );
  23.           case 4:    printf( "     4 4 4 4\n" );
  24.           case 3:    printf( "      3 3 3\n" );
  25.           case 2:    printf( "       2 2\n" );
  26.           case 1:    printf( "        1\n" );
  27.           case 0:    printf( "00000000000000000\n" );    /* Note 3 */
  28.           default :  printf( "-----------------\n" );
  29.      }
  30.      return 0;
  31. }