lldiv() function in C++ STL

The lldiv() is a builtin function in C++ STL which gives us the quotient and remainder of the division of two numbers.

Syntax:

lldiv(n, d)

Parameters: The function accepts two mandatory parameters which are described below:



  • n: It specifies the dividend. The data-type can be long long or long long int.
  • d: It specifies the divisor. The data-type can be long long or long long int.

Return value: The function returns a structure of type lldiv_t which consists of two members: quot and rem, where quot is the quotient and rem is the remainder. The struct is defined as follows:

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

Below programs illustrate the above function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// lldiv() function
#include <cstdlib>
#include <iostream>
using namespace std;
  
int main()
{
    long long n = 1000LL;
    long long d = 50LL;
  
    lldiv_t result = lldiv(n, d);
  
    cout << "Quotient of " << n << "/" << d
         << " = " << result.quot << endl;
  
    cout << "Remainder of " << n << "/" << d
         << " = " << result.rem << endl;
  
    return 0;
}

chevron_right


Output:

Quotient of 1000/50 = 20
Remainder of 1000/50 = 0

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// the lldiv() function
#include <cstdlib>
#include <iostream>
using namespace std;
  
int main()
{
    long long int n = 251987LL;
    long long int d = 68LL;
  
    lldiv_t result = lldiv(n, d);
  
    cout << "Quotient of " << n << "/" << d
         << " = " << result.quot << endl;
    cout << "Remainder of " << n << "/" << d
         << " = " << result.rem << endl;
  
    return 0;
}

chevron_right


Output:

Quotient of 251987/68 = 3705
Remainder of 251987/68 = 47


My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.