remquo() in C++

This function is used to return the remainder(modulus) of 2 floating point numbers mentioned in its arguments and also stores the quotient to the pointer passed to it. The quotient computed is rounded.

remainder = number – rquot * denom
Where rquot is the result of: numerator/denominator, rounded toward the nearest integral value (with halfway cases rounded toward the even number).

Syntax:



long double remquo(long double a, long double b, int* q);
double remquo(double a, double b, int* q);
float remquo(float a, float b, int* q);

    Parameter:

  • a and b are the values of numerator and denominator. q is the pointer in which quotient will be stored.
  • Return:

  • It returns the floating point remainder of numerator/denominator rounded to nearest and stores quotient in q.

    Error:

  1. It is mandatory to give all the three arguments otherwise it will give error no matching function for call to ‘remquo’.
  2. It is mandatory to pass third argument a pointer because it stores address of quotient otherwise it will give error ‘remquo(double&, double&, int&)’
  3. .

Examples:

Input : remquo(12.5, 2.2, &q)
Output : -0.7 and q=6

Explanation:

Input : remquo(-12.5, 2.2, &q)
Output : 0.7 and q=-6

# CODE 1

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP implementation of the above 
// function
#include <cmath>
#include <iostream>
  
using namespace std;
  
int main()
{
    int q;
    double a = 12.5, b = 2.2;
  
    // it will return remainder 
    // and stores quotient in q
    double answer = remquo(a, b, &q);
      
    cout << "Remainder of " << a << "/" 
         << b << " is " << answer << endl;
      
    cout << "Quotient of " << a << "/" 
         << b << " is " << q << endl
         << endl;
  
    a = -12.5;
      
    // it will return remainder 
    // and stores quotient in q
    answer = remquo(a, b, &q);
      
    cout << "Remainder of " << a << "/" << b 
         << " is " << answer << endl;
      
    cout << "Quotient of " << a << "/" << b 
         << " is " << q << endl
         << endl;
  
    b = 0;
      
    // it will return remainder
    // and stores quotient in q
    answer = remquo(a, b, &q);
      
    cout << "Remainder of " << a << "/" << b 
         << " is " << answer << endl;
      
    cout << "Quotient of " << a << "/" << b 
         << " is " << q << endl
         << endl;
  
    return 0;
}

chevron_right


OUTPUT :

Remainder of 12.5/2.2 is -0.7
Quotient of 12.5/2.2 is 6

Remainder of -12.5/2.2 is 0.7
Quotient of -12.5/2.2 is -6

Remainder of -12.5/0 is -nan
Quotient of -12.5/0 is -6

# CODE 2

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP implementation of the
// above function
#include <cmath>
#include <iostream>
  
using namespace std;
  
int main()
{
    int q;
    double a = 12.5;
    int b = 2;
  
    // it will return remainder
    // and stores quotient in q
    double answer = remquo(a, b, &q);
      
    cout << "Remainder of " << a << "/" << b 
         << " is " << answer << endl;
      
    cout << "Quotient of " << a << "/" << b 
         << " is " << q << endl
         << endl;
  
    return 0;
}

chevron_right


OUTPUT :

Remainder of 12.5/2 is 0.5
Quotient of 12.5/2 is 6


My Personal Notes arrow_drop_up

pawanasipugmailcom

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.