This blog is under construction

Monday, 30 April 2012

modf example in C

Header file:
    math.h

Synopsis:
     double modf(double x, double *iptr);

Description:
      It splits the value x into integral and fractional parts.  Returns fractional part and stores the integral part in iptr.


modf function C example:


  #include<stdio.h>
  #include<math.h>
  int main() {
        double x, res, ip;
        printf("Enter the value for x:");
        scanf("%lf", &x);
        res = modf(x, &ip);
        printf("Integral part: %d\tFraction:%lf\n", (int)ip, res);
        printf("x:%lf\n", x);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/math$ ./a.out
  Enter the value for x:56.56
  Integral part: 56    Fraction:0.560000
  x:56.560000



No comments:

Post a Comment