div -- Integer Division

SYNOPSIS
#include <stdlib.h>
div_t div(int numer, int denom);
DESCRIPTION
div
computes the quotient and remainder of numer
divided by
denom
.
RETURN VALUE
div
returns a structure of type div_t
, which contains both the
quotient and remainder. The definition of the div_t
type is
typedef struct {
int rem;
int quot;
} div_t;
The return value is such that
numer == quot * denom + rem
The sign of rem
is the same as the sign of numer
.
EXAMPLE
This example converts an angle in radians to degrees, minutes, and seconds:
#include <math.h>
#include <stdlib.h>
#include <lcmath.h>
main()
{
double rad, angle;
int deg, min, sec;
div_t d;
puts(" Enter any angle in radians: ");
scanf("%lf", &rad);
/* Convert angles to seconds and discard fraction. */
angle = rad * (180 * 60 * 60)/M_PI;
sec = angle;
d = div(sec, 60);
sec = d.rem;
d = div(d.quot, 60);
min = d.rem;
deg = d.quot;
printf("%f radians = %d degrees, %d', %d", n", rad, deg,
min, sec);
}
RELATED FUNCTIONS
ldiv
SEE ALSO
Mathematical Functions