Compute division and remainder in one operation.
Include
<inttypes.h>
Prototype
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
Argument
numer
denom
Return Value
The imaxdiv
function computes the division, numer /
denom
, and remainder, numer % denom
, of the arguments and
returns the results in an imaxdiv_t
structure.
Remarks
If either part of the result cannot be represented, the behavior is undefined.
Example
#include <inttypes.h>
#include <stdio.h>
int main(void)
{
intmax_t numer, denom;
imaxdiv_t result;
numer = 400;
denom = 3;
result = imaxdiv(numer, denom);
printf("The remainder of %" PRIdMAX " divided by %" PRIdMAX " is %" PRIdMAX "\n", numer, denom, result.rem);
}
Example Output
The remainder of 400 divided by 3 is 1