Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>div() divides integers</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 div()                   Divides integers

 #include   <stdlib.h>

  struct div_t div(numer, denom);
  int numer;   Numerator
  int denom;   Denominator

    div() computes the quotient and remainder of the division of the
    numerator numer by the denominator denom. The sign of the quotient is
    the same as that of the algebraic quotient.  The absolute value of
    the quotient is the largest integer that is less than the absolute
    value of the algebraic quotient. If the denominator is 0 the program
    will terminate with an error message.

    Returns:    div() returns a structure of type div_t, defined in
                stdlib.h, with the quotient and remainder as members:

                    struct div_t {
                       int quot:   Quotient
                       int rem;    Remainder
                       };

      Notes:    These are the results of div:

                    numer  denom  quot   remain
                    -----  -----  -----  ------
                       7      3      2       1
                     - 7      3    - 2     - 1
                       7    - 3    - 2       1
                     - 7    - 3      2     - 1

   Portability:     ANSI

 ---------------------------- Example --------------------------------

 This program divides 23 by -3 and prints the remainder and quotient

         #include <stdlib.h>

         main()
         {
            div_t div_result;
            div_result = div(23, -3);
            printf("23 divided by -3 gives a quotient of %d and a remainder
                    of %d\n", div_result.quot, div_result.rem);

         }


See Also: ldiv()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson