The remquo() function in C is part of the standard math library <math.h> and is used to compute the remainder and part of the quotient of the division of two floating-point numbers. This function is particularly useful when we need both the remainder and some information about the quotient simultaneously for further calculations.
Syntax of remquo() in C
double remquo(double x, double y, int *quo);
Parameters of remquo() in C
The remquo() function in C takes the following parameters:
- x: The dividend, a floating-point number.
- y: The divisor, a floating-point number.
- quo: A pointer to an integer where part of the quotient of x divided by y will be stored.
Return Value of remquo() in C
The remquo() function returns the remainder of the division of two floating-point numbers (i.e. division of x/y). The remainder is computed such that:
remainder = x − n × y
Here, n is the integer quotient rounded towards zero.
Examples of remquo() Function in C Language
The following examples illustrates how we can use the remquo() function in C language.
Example 1
The following program demonstrates how to calculate the remainder and part of the quotient of the division of two given numbers using the remquo() function in C.
C
// C Program to calculate the remainder and part of the
// quotient using remquo() function
#include <math.h>
#include <stdio.h>
int main()
{
// Initialize variables to take the input from the user
// and store the results
double x, y, remainder;
int quo;
// Take the input from the user
printf("Enter the dividend: ");
scanf("%lf", &x);
printf("Enter the divisor: ");
scanf("%lf", &y);
// Calculate the remainder and part of the quotient of
// the division of x by y
remainder = remquo(x, y, &quo);
// Print the remainder and part of the quotient
printf("The remainder of %.2lf divided by %.2lf is: "
"%.2lf\n",
x, y, remainder);
printf("Part of the quotient is: %d\n", quo);
return 0;
}
Output
Enter the dividend: 25
Enter the divisor: 4
The remainder of 25.00 divided by 4.00 is: 1.00
Part of the quotient is: 6
Time Complexity: O(1)
Auxiliary Space: O(1)
Example 2
The following program demonstrates how to find the remainder and part of the quotient for different data types in C.
C
// C program to calculate the remainder and part of the
// quotient of different data types in C using remquo()
// function
#include <math.h>
#include <stdio.h>
int main()
{
// Initialize variables of different data types
double x1 = 10.5, y1 = 5.5;
float x2 = 20.5f, y2 = 6.5f;
long double x3 = 30.5l, y3 = 7.5l;
int quo1, quo2, quo3;
// Calculate the remainder using the appropriate remquo
// function for each data type
// remquo function for double
double result1 = remquo(x1, y1, &quo1);
// remquof function for float
float result2 = remquof(x2, y2, &quo2);
// remquol function for long double
long double result3 = remquol(x3, y3, &quo3);
// Print the results
printf("The remainder of %.2f divided by %.2f is %.2f "
"and part of the quotient is %d\n",
x1, y1, result1, quo1);
printf("The remainder of %.2f divided by %.2f is %.2f "
"and part of the quotient is %d\n",
x2, y2, result2, quo2);
printf("The remainder of %.2Lf divided by %.2Lf is "
"%.2Lf and part of the quotient is %d\n",
x3, y3, result3, quo3);
return 0;
}
Output
The remainder of 10.50 divided by 5.50 is -0.50 and part of the quotient is 2
The remainder of 20.50 divided by 6.50 is 1.00 and part of the quotient is 3
The remainder of 30.50 divided by 7.50 is 0.50 and part of the quotient is 4
Time Complexity: O(1)
Auxiliary Space: O(1)
Note: The remquo() Function is available in three variants: remquo() for double, remquof() for float, and remquol() for long double.