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 / divrem.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  974b  |  32 lines

  1. /*                    divrem.c
  2.  *
  3.  *   Synopsis  - Prompts for and accepts input of two integer
  4.  *               values and displays the results of a quotient
  5.  *               and a remainder operation.
  6.  *
  7.  *   Objective - Illustrates the abs() function and one method
  8.  *               of ensuring that the results of these operations
  9.  *               will be the same on different computer systems.
  10.  */
  11.  
  12. /* Include Files */
  13. #include <stdio.h>
  14. #include <stdlib.h>                          /* Note 1 */
  15.  
  16. int main( void )
  17. {
  18.      int a, b;
  19.  
  20.      printf("Enter a positive and a negative integer. ");
  21.      printf("\nSeparate with a space: ");
  22.      scanf("%d %d", &a, &b);
  23.  
  24.                                              /* Note 2 */
  25.      printf("The value of a / b is %d\n",
  26.                                     -(abs(a) / abs(b)));
  27.  
  28.      printf("The value of a %% b is %d\n",   /* Note 3 */
  29.                                     -(abs(a) % abs(b)));
  30.      return 0;
  31. }
  32.