|
|
#include <stdlib.h>struct div_t { int quot; /* Quotient */ int rem; /* Remainder */ }
div_t div(numerator, denominator) int numerator; int denominator;
See the example which follows.
ANSI X3.159-1989 Programming Language -- C
.
#include <stdio.h> #include <stdlib.h> #include <math.h>The example above takes two integers as command line arguments and displays the results of the integer division. This program accepts two arguments on the command line following the program name, then calls div to divide the first argument by the second. Finally, it prints the structure membersmain(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); }
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