### lldiv -- Perform Long Long Division

Format

>     #include <stdlib.h>
>     lldiv_t lldiv(long long int numerator, long long int denominator);

Language Level: Extension
lldiv calculates the quotient and remainder of the division of numerator by denominator.

Return Value
lldiv returns a structure of type lldiv_t, containing both the quotient (long long int quot) and the remainder (long long int rem). If the value cannot be represented, the return value is undefined. If denominator is 0, an exception is raised.

Example
This example uses lldiv to calculate the quotients and remainders for a set of two dividends and two divisors.

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

    int main(void)
    {
       long long int num[2] =  { 45,-45 );
       long long int den[2] =  { 7,-7 );
       lldiv_t ans;       /* lldiv_t is a struct type containing two long long ints:
                             'quot' stores quotient; 'rem' stores remainder  */
       short i,j;

       printf("Results of long long division:\n");
       for (i = 0; i < 2; i++)
          for (j = 0; j < 2; j++) {
             ans = lldiv(num[i], den[j]);
             printf("Dividend: %4lld   Divisor: %4lld   Quotient: %4lld   "
                    "Remainder: %4lld\n", num[i], den[j], ans.quot, ans.rem);
          }
       return 0;

       /****************************************************************************
          The output should be:

          Results of long long division:
          Dividend:   45   Divisor:    7   Quotient:    6   Remainder:    3
          Dividend:   45   Divisor:   -7   Quotient:   -6   Remainder:    3
          Dividend:  -45   Divisor:    7   Quotient:   -6   Remainder:   -3
          Dividend:  -45   Divisor:   -7   Quotient:    6   Remainder:   -3
       ****************************************************************************/
    }

div -- Calculate Quotient and Remainder
ldiv -- Perform Long Division
<stdlib.h>