How to use remquo() math function in C++

In this article, we will learn how to use the remquo() math function in C++. This function is associated with the <cmath> library to find the quotient and remainder of a division. This is a preloaded function that has a specific purpose only to find the remainder and quotient of a given numerator and denominator.

We all know the remainder = number – quotient * denominator.

The syntax: remquo() math function in C++

datatype remainder= remquo (datatype numerator, datatype denominator, datatype* quotient_pointer);

It returns the floating-point remainder of numerator/denominator rounded to nearest and stores quotient in q. It is necessary to give all the three arguments otherwise it will give an error. You also can’t provide 0 as a denominator as it will provide a runtime error.

Please see that there can be many return types for this particular function such as long, double or float.

Algorithm to solve the above problem :

  1. Start
  2. Take input(numerator & denominator) as integer or float or double.
  3. Take remainder=0 and quotient=0.
  4. remainder = remquo ( numerator, denominator, &quotient);
  5. Print remainder and quotient.
  6. End

C++ program to demonstrate remquo() math function

#include <cmath> 
#include <iostream> 
using namespace std; 
int main() 
  int quotient,numerator,denominator,remaindr; 

    cout<<"Insert the numerator : ";
    cout<<"Insert the denominator : ";
    remaindr = remquo(numerator, denominator, &quotient); // the quotient's pointer is used here
  cout << "Quotient of " << numerator << "/"
    << denominator << " is " << quotient <<  endl; 

  cout << "Remainder of " << numerator << "/"
    << denominator << " is " << remaindr<< endl; 
  return 0; 

The output of the above program :

remquo() math function in C++

This is a very simple program. I tried my best to do it in the easiest way possible. Hope you like it. If you have any doubts, please comment below.

Leave a Reply

Your email address will not be published.