#include <stdlib.h> div_t div(int numer, int denom);
div
computes the quotient and remainder of numer
divided by
denom
.
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 + remThe sign of
rem
is the same as the sign of numer
.
#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); }
ldiv
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.