home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / math / intmath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-27  |  1.2 KB  |  38 lines

  1. /* INTMATH.C illustrates integer math functions including:
  2.  *      abs         labs        min         max         div         ldiv
  3.  *
  4.  * See MATH.C for an example of the similar fabs function.
  5.  */
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <math.h>
  10.  
  11. main()
  12. {
  13.     int x, y;
  14.     long lx, ly;
  15.     div_t divres;
  16.     ldiv_t ldivres;
  17.  
  18.     printf( "Enter two integers: " );
  19.     scanf( "%d %d", &x, &y );
  20.  
  21.     printf("Function\tResult\n\n" );
  22.     printf( "abs\t\tThe absolute value of %d is %d\n", x, abs( x ) );
  23.     printf( "min\t\tThe lesser of %d and %d is %d\n", x, y, min( x, y ) );
  24.     printf( "max\t\tThe greater of %d and %d is %d\n", x, y, max( x, y ) );
  25.     divres = div( x, y );
  26.     printf( "div\t\tFor %d / %d, quotient is %d and remainder is %d\n\n",
  27.             x, y, divres.quot, divres.rem );
  28.  
  29.     printf( "Enter two long integers: " );
  30.     scanf( "%ld %ld", &lx, &ly );
  31.  
  32.     printf("Function\tResult\n\n" );
  33.     ldivres = ldiv( lx, ly );
  34.     printf( "labs\t\tThe absolute value of %ld is %ld\n", lx, labs( lx ) );
  35.     printf( "ldiv\t\tFor %ld / %ld, quotient is %ld and remainder is %ld\n",
  36.             lx, ly, ldivres.quot, ldivres.rem );
  37. }
  38.