Name

div
- computes quotient and remainder of an integer division

Library

libc.lib

Synopsis

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

Return values

The div function returns a structure of type div_t that contains two int members named quot (quotient) and rem (remainder).

Detailed description

The div function computes the value num/denom and returns the quotient and remainder in a structure named div_t that contains two int members named quot and rem.

Examples

#include <stdlib.h>
#include <stdio.h>
 
void main( void )
{
 int numer = -14;
 int denom = -3;
 int exp_numer = 0;
    
 /* call to div */
 div_t x = div(numer, denom);
 
 printf("Result->\n Quotient = %d\n Remainder = %d\n", x.quot, x.rem);
                
 exp_numer = (denom * x.quot) + x.rem;
 
 if( exp_numer == (numer) )
    printf("Result is same as the expected output");  
 else
    printf("Unexpected output");
    
 return 0; 
}

         

Output

Result->
Quotient = 4
Remainder = -2
Result is same as the expected output

         

See also

ldiv, lldiv

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top