[Previous]
[Contents]
[Next]

div()

calculate quotient and remainder of a division operation

Synopsis:

#include <stdlib.h>
div_t div( int numer, int denom );

typedef struct {
    int quot;      /* quotient */
    int rem;       /* remainder */
} div_t;

Description:

The div() function calculates the quotient and remainder of the division of the numerator, numer, by the denominator, denom.

Returns:

A structure of type div_t, which contains the fields quot and rem.

Examples:

#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

Classification:

ANSI

Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

ldiv()


[Previous]
[Contents]
[Next]