Math Remainder Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Remainder Function

Math Remainder Function

BLUF: Mastering Math Remainder Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Remainder Function

C++ is renowned for its efficiency. Learn how Math Remainder Function enables low-level control and high-performance computing in the tutorial below.

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 :

Example

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:

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience