div()

Calculate a quotient and remainder

Synopsis:

#include <stdlib.h>

div_t div( int numer, 
           int denom );

Arguments:

numer
The numerator in the division.
denom
The denominator.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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

Returns:

A div_t structure containing the quotient and remainder:

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

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 );
}

int main( void )
{
    print_time( 130 );
    
    return EXIT_SUCCESS;
}

produces the output:

It took 2 minutes and 10 seconds

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes