C library function - modf()


Advertisements

Description

The C library function double modf(double x, double *integer) returns the fraction component (part after the decimal), and sets integer to the integer component.

Declaration

Following is the declaration for modf() function.

double modf(double x, double *integer)

Parameters

  • x − This is the floating point value.

  • integer − This is the pointer to an object where the integral part is to be stored.

Return Value

This function returns the fractional part of x, with the same sign.

Example

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

#include<stdio.h>
#include<math.h>

int main () {
   double x, fractpart, intpart;

   x = 8.123456;
   fractpart = modf(x, &intpart);

   printf("Integral part = %lf\n", intpart);
   printf("Fraction Part = %lf \n", fractpart);
   
   return(0);
}

Let us compile and run the above program that will produce the following result −

Integral part = 8.000000
Fraction Part = 0.123456 
math_h.htm

Useful Video Courses


Video

JCL Online Training

12 Lectures 2 hours

Nishant Malik

Video

COBOL Online Training

12 Lectures 2.5 hours

Nishant Malik

Video

CRO Online Training

48 Lectures 6.5 hours

Asif Hussain

Video

Customer Service Online Training

12 Lectures 2 hours

Richa Maheshwari

Video

Cultivation of Crops

20 Lectures 3.5 hours

Vandana Annavaram

Video

Eclipse Online Training

44 Lectures 1 hours

Amit Diwan

Advertisements