- Related Questions & Answers
- remainder() in C++
- C++ Program to Find Quotient and Remainder
- C Program to Compute Quotient and Remainder?
- C++ Program for quotient and remainder of big number
- C# program to accept two integers and return the remainder
- Program to find remainder without using modulo or % operator in C++
- Java program to compute Remainder and Quotient
- Program to find Quotient and Remainder in Java
- Modulo / Remainder in Arduino
- Program to find remainder when large number is divided by 11 in C++
- Program to find remainder when large number is divided by r in C++
- Python Program to Read Two Numbers and Print Their Quotient and Remainder
- Find N % (Remainder with 4) for a large value of N in C++
- How to perform integer division and get the remainder in JavaScript?
- How to render the remainder of the document as preformatted plain text in HTML?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will be discussing the working, syntax, and examples of remainder() function in C++.

remainder() function is an inbuilt function in C++ STL, which is defined in <cmath> header file. remainder() is used to find the remainder of the parameters.

This function takes two arguments, one for the numerator and second for the and computes its remainder and returns a floating-point which is rounded to the nearest.

This function computes −

remainder = numerator – roundquot * denominator;

In which “remainder” is the resulting numerator being the first argument and denominator is the second argument and roundquot is the rounded off (toward the even number) result of numerator/denominator.

This function is similar to the fmod function which rounds of the quotient towards zero.

double remainder(double numerator, double denominator);

The function accepts the following parameter(s) −

**numerator**− The value of quotient’s numerator.**denominator**− Quotient’s denominator.

This function returns the remainder of numerator and denominator if the numerator is zero the function will also return zero. When the denominator is zero either the function returns zero or gives a domain error.

**Input **

remainder(51, 5);

**Output **

1

#include <cmath> #include <iostream> using namespace std; int main(){ int numerator = 51; int denominator = 5, remainder_ans; remainder_ans = remainder(numerator, denominator); cout<<"Value of Remainder is " <<numerator << "/" << denominator << " is: " << remainder_ans << endl; return 0; }

If we run the above code it will generate the following output −

Value of Remainder is 51/5 is: 1

**//when the denominator is 0 output will be −**

#include <cmath> #include <iostream> using namespace std; int main(){ int numerator = 51; int denominator = 0, remainder_ans; remainder_ans = remainder(numerator, denominator); cout<<"Value of Remainder is " << numerator << "/" << denominator << " is: " << remainder_ans << endl; return 0; }

If we run the above code it will generate the following output −

Value of Remainder is 51/0 is: -2147483648 //garbage value

Advertisements