In this C++ tutorial, you will learn how to find floating point remainder of division x by y, using remquo() function of cmath, with syntax and examples.
C++ remquo()
C++ remquo() returns floating point remainder of division x by y, and also stores the quotient to the pointer passed to it as third argument.
Syntax
The syntax of C++ remquo() is
remquo(x, y, q)
where
Parameter | Description |
---|---|
x | Numerator. A double, float, long double, or integral type value. |
y | Denominator. A double, float, long double, or integral type value. |
q | Integer pointer to store quotient of the division x/y. |
Returns
The return value depends on the type of value passed for parameters x and y.
The return value of remquo() is
- double if x and y are double or integral type.
- float if x and y are float.
- long double if x and y are long double.
The synopsis of remquo() function is
double remquo(double x, double y, int* q); float remquo(float x, float y, int* q); long double remquo(long double x, long double y, int* q); double remquo(Type1 x, Type2 y, int* q); // for combinations of integral types
remquo() is a function of cmath library. Include cmath library at the start of program, if using remquo() function.
Example
In this example, we read two values from user, into variables x and y for numerator and denominator respectively, and compute the compute the floating point remainder of division x by y using remquo() function.
C++ Program
#include <iostream> #include<cmath> using namespace std; int main() { double x, y; cout << "Enter numerator (x) : "; cin >> x; cout << "Enter denominator (y) : "; cin >> y; int q; double result = remquo(x, y, &q); cout << "Floating point remainder : " << result << endl; cout << "Quotient : " << q << endl; }
Output
Enter numerator (x) : 5.21 Enter denominator (y) : 1.2 Floating point remainder : 0.41 Quotient : 4 Program ended with exit code: 0
Enter numerator (x) : 10 Enter denominator (y) : 2.4 Floating point remainder : 0.4 Quotient : 4 Program ended with exit code: 0
Enter numerator (x) : 0 Enter denominator (y) : 0 Floating point remainder : nan Quotient : 0 Program ended with exit code: 0
Enter numerator (x) : nan Enter denominator (y) : 5 Floating point remainder : nan Quotient : 0 Program ended with exit code: 0
Conclusion
In this C++ Tutorial, we learned the syntax of C++ remquo(), and how to use this function to find floating point remainder, with the help of examples.