div

Calculates the quotient and remainder (function or macro)

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:Mathematical Computation

Syntax

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

Parameters

numer
(IN) Specifies the numerator.
denom
(IN) Specifies the denominator.

Return Values

div returns a structure of type div_t, which contains the fields quot and rem.

Remarks

The div function or macro calculates the quotient and remainder of the division of the numerator numer by the denominator denom.

See Also

ldiv

Example

  #include <stdlib.h>  
  #include <stdio.h>  
   
  void print_time (int seconds)  
  {  
     auto div_t min_sec;  
     min_sec = div (seconds, 60);  
     printf ("It took %d minutes and %d seconds\n",  
        min_sec.quot, min_sec.rem);  
  }
  

produces the following:

  It took 2 minutes and 23 seconds