
#include <stdlib.h> ldiv_t ldiv(long int numer, long int denom);
ldiv computes the quotient and remainder of numer divided by
denom.
div returns a structure of type ldiv_t, which contains both the
quotient and remainder. The definition of the ldiv_t type is
typedef struct {
long rem;
long quot;
}ldiv_t;
The return value is such that
numer == quot * denom + rem
The sign of rem is the same as the sign of numer.
ldiv:
#include <math.h>
#include <stdlib.h>
#include <lcmath.h>
main()
{
double rad, angle;
long deg, min, sec;
ldiv_t d;
puts(" Enter any angle in radians: ");
scanf("%f", &rad);
/* Convert angles to seconds and discard fraction. */
angle = rad * (180 * 60 * 60)/M_PI;
sec = angle;
d = ldiv(sec, 60L);
sec = d.rem;
d = ldiv(d.quot, 60L);
min = d.rem;
deg = d.quot;
printf("%f radians = %ld degrees, %ld, %ldn", rad,
deg, min, sec);
}
div
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.