Chapter Contents |
Previous |
Next |
ldiv |
Portability: | ISO/ANSI C conforming |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <stdlib.h> ldiv_t ldiv(long int numer, long int denom);
DESCRIPTION |
ldiv
computes the quotient and remainder of
numer
divided by
denom
.
RETURN VALUE |
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;
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 using
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, %ld\n", rad, deg, min, sec); }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.