This function is used to return the remainder(modulus) of 2 floating point numbers mentioned in its arguments and also stores the quotient to the pointer passed to it. The quotient computed is rounded. remainder = number – rquot * denom Where rquot is the result of: numerator/denominator, rounded toward the nearest integral value (with halfway cases rounded toward the even number). Syntax:
long double remquo(long double a, long double b, int* q);
double remquo(double a, double b, int* q);
float remquo(float a, float b, int* q);
a and b are the values of numerator and denominator. q is the pointer in which quotient will be stored.
Return:
It returns the floating point remainder of numerator/denominator rounded to nearest and stores quotient in q.
Error:
- It is mandatory to give all the three arguments otherwise it will give error no matching function for call to 'remquo'.
- It is mandatory to pass third argument a pointer because it stores address of quotient otherwise it will give error 'remquo(double&, double&, int&)'
Time Complexity: O(1)
Space Complexity: O(1)
Examples:
Input : remquo(12.5, 2.2, &q)
Output : -0.7 and q=6
Explanation:
Input : remquo(-12.5, 2.2, &q)
Output : 0.7 and q=-6
# CODE 1
CPP
// CPP implementation of the above
// function
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int q;
double a = 12.5, b = 2.2;
// it will return remainder
// and stores quotient in q
double answer = remquo(a, b, &q);
cout << "Remainder of " << a << "/"
<< b << " is " << answer << endl;
cout << "Quotient of " << a << "/"
<< b << " is " << q << endl
<< endl;
a = -12.5;
// it will return remainder
// and stores quotient in q
answer = remquo(a, b, &q);
cout << "Remainder of " << a << "/" << b
<< " is " << answer << endl;
cout << "Quotient of " << a << "/" << b
<< " is " << q << endl
<< endl;
b = 0;
// it will return remainder
// and stores quotient in q
answer = remquo(a, b, &q);
cout << "Remainder of " << a << "/" << b
<< " is " << answer << endl;
cout << "Quotient of " << a << "/" << b
<< " is " << q << endl
<< endl;
return 0;
}
OUTPUT :
Remainder of 12.5/2.2 is -0.7
Quotient of 12.5/2.2 is 6
Remainder of -12.5/2.2 is 0.7
Quotient of -12.5/2.2 is -6
Remainder of -12.5/0 is -nan
Quotient of -12.5/0 is -6
# CODE 2
CPP
// CPP implementation of the
// above function
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int q;
double a = 12.5;
int b = 2;
// it will return remainder
// and stores quotient in q
double answer = remquo(a, b, &q);
cout << "Remainder of " << a << "/" << b
<< " is " << answer << endl;
cout << "Quotient of " << a << "/" << b
<< " is " << q << endl
<< endl;
return 0;
}
OUTPUT :
Remainder of 12.5/2 is 0.5
Quotient of 12.5/2 is 6
Similar Reads
Queue in C++ STL In C++, queue container follows the FIFO (First In First Out) order of insertion and deletion. According to it, the elements that are inserted first should be removed first. This is possible by inserting elements at one end (called back) and deleting them from the other end (called front) of the dat
4 min read
std::quoted in C++ 14 std::quoted is an I/O manipulator function that was introduced in C++ 14 as the part of <iomanip> library. Its primary purpose is to handle the quoted string in the input and output operations. In this article, we will learn about the std::quoted manipulator, how it works and how to use it in
5 min read
I/O Redirection in C++ In C++, input and output operations are done in the form of sequence of bytes called stream through the stream objects like cin and cout. These objects use different components such as buffers, streams, etc. to efficiently read and write data to standard input and output devices such as keyboard and
6 min read
deque cbegin() in C++ STL The cbegin() method in deque is a function in C++ STL which returns an iterator pointing to the first element of the container. Syntax: deque_name.cbegin() Return value: It returns a constant iterator pointing to the first element of the deque. This means, that the iterator can be used to traverse t
2 min read
transform() in C++ STL In C++, transform() is a built-in STL function used to apply the given operation to a range of elements and store the result in another range. Letâs take a look at a simple example that shows the how to use this function:C++#include <bits/stdc++.h> using namespace std; int main() { vector<i
4 min read
goto Statement in C++ The goto statement in C++ is a control flow statement that provides for an unconditional jump to the same function's predefined label statement. In simple terms, the goto is a jump statement transfers the control flow of a program to a labeled statement within the scope of the same function, breakin
5 min read