C++ <cinttypes> - imaxdiv() Function
The C++ <cinttypes> 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; };
Example:
The example below shows the usage of <cinttypes> imaxdiv() function.
#include <iostream> #include <cinttypes> using namespace std; int main (){ imaxdiv_t result = imaxdiv(50, 17); cout<<"imaxdiv(50, 17) gives quotient = "<< result.quot<<" and remainder = "<< result.rem<<"\n"; return 0; }
The output of the above code will be:
imaxdiv(50, 17) gives quotient = 2 and remainder = 16
❮ C++ <cinttypes> Library