Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS® UNIX |
both | OS/390 V2R10 |
#include <stdio.h>
long long lldiv(long long numer, long long denom);
Calculates the quotient and remainder of the division of numerator by denominator.
Returns a structure of type lldiv_t, containing both the quotient long long quot and the remainder long long rem.
If the value cannot be represented, the returned value is undefined. If denominator is 0, a divide by 0 exception is raised.
/*
This example uses the
lldiv() function to calculate the quotients and
remainders for a set of two dividends and two divisors.
*/
#define _LONG_LONG 1
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
long long num[2] = {45,-45};
long long den[2] = {7,-7};
lldiv_t ans; /* lldiv_t is a struct type containing
two long long int fields:
'quot' stores quotient; 'rem' stores remainder */
short i,j;
printf("Results of long division:\n");
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
{
ans = lldiv(num[i], den[j]);
printf("Dividend: %6lld Divisor: %6lld", num[i], den[j]);
printf(" Quotient: %6lld Remainder: %6lld\n", ans.quot,
ans.rem);
}
}
Results of 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