C Standard Library

C <inttypes.h> - imaxdiv() Function



The C <inttypes.h> imaxdiv() function computes both the quotient and the remainder of the division of the integral numerator numer by the integral denominator denom.

Syntax

imaxdiv_t div (intmax_t numer, intmax_t denom); 

Parameters

numer Specify an integral value for numerator.
denom Specify an integral value for denominator.

Return Value

Returns both the remainder and the quotient can be represented as objects of type imaxdiv_t defined as follows:

struct imaxdiv_t { intmax_t quot; intmax_t rem; };

or 

struct imaxdiv_t { intmax_t rem; intmax_t quot; };

Note: This function is equivalent to div() function for intmax_t.

Example:

The example below shows the usage of <inttypes.h> imaxdiv() function.

#include <stdio.h>
#include <inttypes.h>
 
int main (){
  imaxdiv_t result = imaxdiv(50, 17);

  printf("imaxdiv_t(50, 17) gives quotient = %" PRIdMAX " and remainder = %" PRIdMAX "\n",
         result.quot, result.rem);
  
  return 0;
}

The output of the above code will be:

imaxdiv(50, 17) gives quotient = 2 and remainder = 16

❮ C <inttypes.h> Library