home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap03 / math.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-06  |  784 b   |  26 lines

  1. /* math.c -- shows arithmetic and       */
  2. /*           precedence via expressions */
  3.  
  4. main()
  5. {
  6.     int a = 10, b = 4, c = 2;
  7.  
  8.     /* simple arithmetic expressions */
  9.     printf("99 + 2 = %d\n", 99 + 2);  /* ints */
  10.     printf("5 - 12 = %d\n", 5 - 12);
  11.     printf("7.25 + 3.5 = %f\n", 7.25 + 3.5);
  12.                                         /* floats */
  13.  
  14.     /* compare presedence on these */
  15.     printf("20 * 20 + 40 = %d\n", 20 * 20 + 40);
  16.     printf("20 * (20 + 40) = %d\n", 20 * (20 + 40));
  17.     printf("a * a - c + b = %d\n", a * a - c + b);
  18.     printf("a * (a - (c + b)) = %d\n",
  19.             a * (a - (c + b)));
  20.  
  21.     /* compare integer and float division */
  22.  
  23.     printf("Integers: 5 / 2 = %d\n", 5 / 2);
  24.     printf("Floats: 5.0 / 2.0 = %f\n", 5.0 / 2.0);
  25. }
  26.