home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch1 / compound.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  926b  |  34 lines

  1. /*                         compound.c
  2.  *
  3.  *   Synopsis  - Uses compound assignment to change the value of
  4.  *               an integer variable a and displays the changed
  5.  *               value with printf().
  6.  *
  7.  *   Objective - Illustrates compound assignment in C with
  8.  *               several different arithmetic operations.
  9.  */
  10.  
  11. #include <stdio.h>
  12.  
  13. int main( void )
  14. {
  15.      int a = 0;
  16.  
  17.      a += 4;                                       /* Note 1 */
  18.      printf("a is %d.\n", a);
  19.  
  20.      a *= 3;                                      /* Note 2 */
  21.      printf("a is now %d.\n", a);
  22.  
  23.      a -= 4;                                      /* Note 3 */
  24.      printf("a is now %d.\n", a);
  25.  
  26.      a /= 2;                                      /* Note 4 */
  27.      printf("a is now %d.\n", a);
  28.  
  29.      a %= 5;                                      /* Note 5 */
  30.      printf("a is now %d.\n", a);
  31.  
  32.      return 0;
  33. }
  34.