Easy Tutorial
❮ C Passing Pointers To Functions C Input Output ❯

C Library Function - ldiv()

C Standard Library - <stdlib.h>

Description

The C library function div_t div(long int numer, long int denom) divides numer (numerator) by denom (denominator).

Declaration

Below is the declaration for the ldiv() function.

div_t div(long int numer, long int denom)

Parameters

Return Value

The function returns a value defined in the <cstdlib> structure, which has two members: long quot; long rem;.

Example

The following example demonstrates the use of the ldiv() function.

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

int main ()
{
   ldiv_t output;

   output = ldiv(100000L, 30000L);

   printf("Quotient = %ld\n", output.quot);

   printf("Remainder = %ld\n", output.rem);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

Quotient = 3
Remainder = 10000

C Standard Library - <stdlib.h>

❮ C Passing Pointers To Functions C Input Output ❯