|
|
#include <stdlib.h>struct ldiv_t { long quot; /* Quotient */ long rem; /* Remainder */ } ldiv(numerator, denominator) long numerator; long denominator;
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.
#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.
ANSI X3.159-1989 Programming Language -- C .