w3resource

C modf() function

C modf() function - Floating-point remainder value function

Syntax:

double modf(double x, double *iptr)

The modf() function is used to break down the floating-point value x into fractional and integral parts.

Parameters:

Name Description Required /Optional
x Floating-point values. Required
iptr Floating-point values. Required

Return value from modf()

  • Returns the signed fractional portion of x.

Example: modf() function

The following example shows the usage of modf() function.


#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double x, y, d;
 
   x = -14.876;
   y = modf(x, &d);
 
   printf("x = %lf\n", x);
   printf("Integral part = %lf\n", d);
   printf("Fractional part = %lf\n", y);
   x = 7654.887;
   y = modf(x, &d);
 
   printf("\nx = %lf\n", x);
   printf("Integral part = %lf\n", d);
   printf("Fractional part = %lf\n", y);
}

Output:

x = -14.876000
Integral part = -14.000000
Fractional part = -0.876000

x = 7654.887000
Integral part = 7654.000000
Fractional part = 0.887000

C Programming Code Editor:

Previous C Programming: C log10()
Next C Programming: C pow()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming/math/c-modf.php