Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ div(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ldiv(S)


 div(S)                         6 January 1993                         div(S)


 Name

    div - divides integers

 Syntax


    cc  . . .  -lc


    #include <stdlib.h>

    struct div_t {
           int quot;       /* Quotient   */
           int rem;        /* Remainder  */
           }

    div_t div(numerator, denominator)
    int numerator;
    int denominator;


 Description

    The div function divides numerator by denominator, computing the quotient
    and the remainder.  The sign of the quotient is the same as that of the
    mathematical quotient. Its absolute value is the largest integer that is
    less than the absolute value of the mathematical quotient. If the denomi-
    nator is zero, the program terminates with an error message.

    See the example which follows.

 Return value

    The div function returns a structure of type divt, comprising both the
    quotient and the remainder.  The structure is defined in stdlib.h.

 See also

    ldiv(S)

 Standards conformance

    div is conformant with:
    ANSI X3.159-1989 Programming Language -- C.

 Example


    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    main(argc, argv)
    int argc;
    char **argv;
            {
            int x,y;
            div_t div_result;
            x = atoi(argv[1]);
            y = atoi(argv[2]);
            printf("x is %d, y is %d\n", x,y);
            div_result = div(x,y);
            printf("The quotient is %d, and the remainder is %d\n",
                    div_result.quot, div_result.rem);
    }

    The example above takes two integers as command line arguments and dis-
    plays the results of the integer division. This program accepts two argu-
    ments on the command line following the program name, then calls div to
    divide the first argument by the second. Finally, it prints the structure
    members quot and rem.

    Assuming the executable file is named tdiv, it might be executed as:

       tdiv 5 2


    The output would read:

       x is 5, y is 2
       The quotient is 2, and the remainder is 1



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026