Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ldiv

Computes the quotient and remainder of a long integer.

ldiv_t ldiv(
   long int numer,
   long int denom 
);

Parameters

numer
Numerator.
denom
Denominator.

Return Value

ldiv returns a structure of type ldiv_t that comprises both the quotient and the remainder.

Remarks

The ldiv function divides numer by denom, computing the quotient and remainder. The sign of the quotient is the same as that of the mathematical quotient. The absolute value of the quotient is the largest integer that is less than the absolute value of the mathematical quotient. If the denominator is 0, the program terminates with an error message. ldiv is the same as div, except that the arguments of ldiv and the members of the returned structure are all of type long int.

The ldiv_t structure, defined in STDLIB.H, contains long int quot, the quotient, and long int rem, the remainder.

Requirements

Routine Required header Compatibility
ldiv <stdlib.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_ldiv.c

#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int main( void )
{
   long x = 5149627, y = 234879;
   ldiv_t div_result;

   div_result = ldiv( x, y );
   printf( "For %ld / %ld, the quotient is ", x, y );
   printf( "%ld, and the remainder is %ld\n", 
            div_result.quot, div_result.rem );
}

Output

For 5149627 / 234879, the quotient is 21, and the remainder is 217168

See Also

Floating-Point Support Routines | div | Run-Time Routines and .NET Framework Equivalents

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.