C++ Standard Library C++ STL Library

C++ <cstdlib> - lldiv() Function



The C++ <cstdlib> lldiv() function computes both the quotient and the remainder of the division of the integral numerator numer by the integral denominator denom.

Syntax

lldiv_t lldiv (long long int numer, long long int 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 lldiv_t defined as follows:

struct lldiv_t { long long quot; long long rem; };

or 

struct lldiv_t { long long rem; long long quot; };

Example:

The example below shows the usage of <cstdlib> lldiv() function.

#include <iostream>
#include <cstdlib>
using namespace std;
 
int main (){
  lldiv_t result = lldiv(50, 17);

  cout<<"lldiv(50, 17) gives quotient = "<<
      result.quot<<" and remainder = "<< 
      result.rem<<"\n";
  
  return 0;
}

The output of the above code will be:

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

❮ C++ <cstdlib> Library