Facebook Page Twitter Page LinkedIn Page
× C Standard Library

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


ldiv_t ldiv (long int numer, long int denom);


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 ldiv_t defined as follows:

struct ldiv_t { long quot; long rem; };


struct ldiv_t { long rem; long quot; };


The below example shows the usage of <stdlib.h> ldiv() function.

#include <stdio.h>
#include <stdlib.h>
int main (){
  ldiv_t result = ldiv(50, 17);

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

The output of the above code will be:

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

❮ C <stdlib.h> Library