ldiv (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Computes the quotient and remainder of a long integer.

ldiv_t ldiv(    long intnumer,    long intdenom);

Parameters

  • numer
    Numerator.
  • denom
    Denominator.

Return Values

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 longint.

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

Example

/* LDIV.C: This program takes two long integers
 * as command-line arguments and displays the
 * results of the integer division.
 */

#include <stdlib.h>

void 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

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

div

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.