Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/d/div.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/d/div.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/d/div.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/d/div.html on line 8

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

See also:

ldiv()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/d/div.html on line 158

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/d/div.html on line 158