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>ldiv() divides long integers</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ldiv()                  Divides long integers

 #include   <stdlib.h>

  struct ldiv_t ldiv(numer, denom);
  long int numer;   Numerator
  long int denom;   Denominator

    ldiv() 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:    ldiv() returns a structure of type ldiv_t, defined in
                stdlib.h, with the quotient and remainder as members:

                    struct ldiv_t {
                       long int quot:   Quotient
                       long int rem;    Remainder
                       };

      Notes:    These are the results of ldiv:

                    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 -147483647 by 376 and prints the remainder and quotient

           #include <stdlib.h>

           main()
           {
              ldiv_t div_result;
              div_result = ldiv(-147483647, 376l);
              printf("-147483647 divided by 376 gives\n");
              printf("a quotient of %ld and a remainder of %ld\n",
                       div_result.quot, div_result.rem);

           }


See Also: div()

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