calculate quotient and remainder of a division operation
#include <stdlib.h> div_t div( int numer, int denom ); typedef struct { int quot; /* quotient */ int rem; /* remainder */ } div_t;
The div() function calculates the quotient and remainder of the division of the numerator, numer, by the denominator, denom.
A structure of type div_t, which contains the fields quot and rem.
#include <stdio.h> #include <stdlib.h> void print_time( int seconds ) { div_t min_sec; min_sec = div( seconds, 60 ); printf( "It took %d minutes and %d seconds\n", min_sec.quot, min_sec.rem ); } void main() { print_time( 130 ); }
produces the output:
It took 2 minutes and 10 seconds
ANSI
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |