Facebook Page Twitter Page LinkedIn Page
× C Standard Library


The C <math.h> remquo() function is used to return the floating-point remainder of x/y (rounded to nearest integer). The function additionally stores the quotient internally which used to determine the result. This can be mathematically expressed as below:

fmod = x - q * y

Where q is the result of x/y rounded towards nearest integer (with halfway cases rounded toward the even number).

Note: The remainder function is similar to the remquo function except the does not stores quotient internally.

Syntax

double remquo (double x, double y, int* q);
float remquof (float x, float y, int* q);
long double remquol (long double x, long double y, int* q);               

Parameters

x Specify the value of numerator.
y Specify the value of denominator.
q Specify the pointer to the quotient calculated internally and used to determine the remainder.

Return Value

Returns remainder of x/y. If the remainder is zero, its sign will be same as that of x and value stored in q will be unspecified. If y is zero, the function may either return zero or cause a domain error (depending on the library implementation).

Example:

In the below example, remquo() function is used to find out the remainder of a given division.

#include <stdio.h>
#include <math.h>
 
int main (){
  double x, y;
  int q;
  x = 23;
  y = 4;

  double result = remquo(x, y, &q);
  
  printf("numerator = %lf\n", x);
  printf("denominator = %lf\n", y);
  printf("remainder = %lf\n", result);
  printf("quotient = %i\n", q);
 
  return 0;
}

The output of the above code will be:

numerator = 23.000000
denominator = 4.000000
remainder = -1.000000
quotient = 6

❮ C <math.h> Library