Name
ldiv - Divides long integers.
Syntax
#include <stdlib.h>
struct ldiv_t
{
long int quot; /* Quotient */
long int rem; /* Remainder */
} ldiv(numerator, denominator)
long int numerator;
long int denominator;
Description
The ldiv routine 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 which is less than the absolute
value of the mathematical quotient. If the denominator is
zero, the program terminates with an error message.
The ldiv function is similar to the div function, the
difference being that the arguments and the members of the
returned structure are all of type long int.
Return Value
The ldiv function returns a structure of type ldiv_t ,
comprising both the quotient and the remainder. The
structure is defined in stdlib.h.
See Also
div(DOS)
Example
#include <stdlib.h> #include <math.h>
main(argc, argv) int argc; char **argv;
{
long int x,y;
ldiv_t div_result;
x = atol(argv[1]);
y = atol(argv[2]);
printf("x is %ld, y is %ld\n", x,y);
div_result = ldiv(x,y);
printf("The quotient is %ld, and the remainder is
%ld\n",
div_result.quot, div_result.rem);
}
This program takes two long integers as command line
arguments and displays the results of the integer division.
(printed 6/18/89)