ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

remquo() Function with Example in C++

C++ remquo() function: Here, we are going to learn about the remquo() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on May 25, 2020

C++ remquo() function

remquo() function is a library function of cmath header. It is used to calculate the remainder and quotient, this function is the same as the remainder() function, but this function also stores the quotient that can be used further. It accepts three parameters (numerator, denominator, and quotient) and returns the remainder, assigns the quotient in the third parameter which should be a pointer.

Syntax of remquo() function:

C++11:

     double remquo (double numer     , double denom     , int* quot);
      float remquo (float numer      , float denom      , int* quot);
long double remquo (long double numer, long double denom, int* quot);
     double remquo (Type1 numer      , Type2 denom      , int* quot);

Parameter(s):

  • numer, denom – represent the values of numerator and denominator.
  • *quot– represents an integer pointer to store the quotient.

Return value:

It returns the remquo.

Note:

  • If the remquo is 0, then its sign is the same as the sign of numer.
  • If the value of denom is 0, the result may either 0 or it may cause a domain error.

Example:

    Input:
    double x = 10.34;
    double y = 2.5;
    double rem;
    int quo;
    
    Function call:
    remquo(x, y, &quo);
    
    Output:
    rem = 0.34
    quo = 4

C++ code to demonstrate the example of remquo() function

// C++ code to demonstrate the example of
// remquo() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    double x;
    double y;
    double r;
    int q;

    x = 10;
    y = 2;

    r = remquo(x, y, &q);
    cout << "numerator  : " << x << endl;
    cout << "denominator: " << y << endl;
    cout << "remainder  : " << r << endl;
    cout << "quotient   : " << q << endl;
    cout << endl;

    x = 10.34;
    y = 2.5;

    r = remquo(x, y, &q);
    cout << "numerator  : " << x << endl;
    cout << "denominator: " << y << endl;
    cout << "remainder  : " << r << endl;
    cout << "quotient   : " << q << endl;
    cout << endl;

    x = -10.02;
    y = 2.3;

    r = remquo(x, y, &q);
    cout << "numerator  : " << x << endl;
    cout << "denominator: " << y << endl;
    cout << "remainder  : " << r << endl;
    cout << "quotient   : " << q << endl;
    cout << endl;

    x = 10.23;
    y = -2.0;

    r = remquo(x, y, &q);
    cout << "numerator  : " << x << endl;
    cout << "denominator: " << y << endl;
    cout << "remainder  : " << r << endl;
    cout << "quotient   : " << q << endl;
    cout << endl;

    return 0;
}

Output

numerator  : 10
denominator: 2
remainder  : 0
quotient   : 5

numerator  : 10.34
denominator: 2.5
remainder  : 0.34
quotient   : 4

numerator  : -10.02
denominator: 2.3
remainder  : -0.82
quotient   : -4

numerator  : 10.23
denominator: -2
remainder  : 0.23
quotient   : -5

Reference: C++ remquo() function

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.