div() - Utility Function
How is Utility function "div()" used in C++?
How to perform Integer Division in C++?
is a Utility Function that returns the quotient and remainder in the "div_t" type for integers. For long integers the quotient and remainder is returned using the "ldiv_t" type defined by the header file.
Syntax to Integer Division:
div_t div(int numerator, int denominator);
ldiv_t div(long numerator, long denominator);
int main ()
printf ("The quotient of 13/2 is: %d\n", r.quot);
printf ("The remainder is:%d", r.rem);
The quotient of 13/2 is: 6
The remainder is: 1
In the above example div() is used to perform integer division and find the quotient and the remainder of 13 is divided by 2.