C++ Math remainder
The function calculates the decimal remainder of the division between the numerator and the denominator, rounded to the nearest whole number.
Formulae of remainder :
Remainder = numerator - (r*denominator)
where, r represents the result of dividing the numerator by the denominator, and this value is then rounded to the nearest whole number.
Syntax
Consider a dividend 'n' and divisor 'd'. The syntax should be as follows:
return_type remainder(data_type n,data_type d);
Note: The return_type can be float, double or long double.
Parameter
n : Value of the numerator.
d : Value of the denominator.
Return value
It returns the floating point remainder n/d.
Example 1
Let's see a simple example.
#include <iostream>
#include<math.h>
#include <cfenv>
using namespace std;
int main()
{
float n=5.7;
float d=8.9;
std::cout << "Values of numerator and denominator are :" <<n <<" , "<<d<<std::endl;
cout<<"Remainder is :"<<remainder(n,d);
return 0;
}
Output:
Values of numerator and denominator are :5.7 , 8.9
Remainder is :-3.2