Home >>C Math Functions >C math modf() function
C math modf() function is used to return the fraction component (part after the decimal) and set integer to the integer component. It takes two different arguments and return a value with same sign.
Syntax:double modf(double x, double *integer)
Parameter | Description |
---|---|
x | It is the floating point value. |
integer | It is the pointer to an object where the integral part is to be stored. |
#include <stdio.h>
#include <math.h>
int main ()
{
double x, fractpart, intpart;
x = 8.123;
fractpart = modf(x, &intpart);
printf("Integral part = %lf\n", intpart);
printf("Fraction Part = %lf \n", fractpart);
return(0);
}
#include <stdio.h>
#include <math.h>
int main ()
{
double x, fractpart, intpart;
x = 340.1283;
fractpart = modf(x, &intpart);
printf("Integral part = %lf\n", intpart);
printf("Fraction Part = %lf \n", fractpart);
return(0);
}