C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
INTMATH.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* INTMATH.C illustrates integer math functions including:
 *      abs         labs      __min       __max         div         ldiv
 *
 * See MATH.C for an example of fabs and other floating-point functions.
 */
 
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
 
void main()
{
    int x, y;
    long lx, ly;
    div_t divres;
    ldiv_t ldivres;
 
    printf( "Enter two integers: " );
    scanf( "%d %d", &x, &y );
 
    printf("Function\tResult\n\n" );
    printf( "abs\t\tThe absolute value of %d is %d\n", x, abs( x ) );
    printf( "__min\t\tThe lesser of %d and %d is %d\n", x, y, __min( x, y ) );
    printf( "__max\t\tThe greater of %d and %d is %d\n", x, y, __max( x, y ) );
    divres = div( x, y );
    printf( "div\t\tFor %d / %d, quotient is %d and remainder is %d\n\n",
            x, y, divres.quot, divres.rem );
 
    printf( "Enter two long integers: " );
    scanf( "%ld %ld", &lx, &ly );
 
    printf("Function\tResult\n\n" );
    ldivres = ldiv( lx, ly );
    printf( "labs\t\tThe absolute value of %ld is %ld\n", lx, labs( lx ) );
    printf( "ldiv\t\tFor %ld / %ld, quotient is %ld and remainder is %ld\n",
            lx, ly, ldivres.quot, ldivres.rem );
}
                                    -♦-