Math Remainder Function

C++ Math remainder

The function finds the floating point remainder of numerator/denominator (rounded to the nearest integer value).

Formulae of remainder :

Example

Remainder = numerator - (r*denominator)

where, r = numerator/denominator and it is rounded to the nearest integral value.

Syntax

Consider a numerator 'n' and denominator 'd'. Syntax would be:

Example

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.

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:

Output

Values of numerator and denominator are :5.7 , 8.9
Remainder is :-3.2

Input Required

This code uses input(). Please provide values below: