C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C programs » math.h header file functions

modf() function of math.h in C

In this article, we are going to learn about the use modf() function of math.h header file and use it with the help of an example.
Submitted by Manu Jemini, on April 01, 2018

This function solves some of the basic problems of mathematics, which will be much complex in programming.

The modf() function takes two parameters, first is the floating point value which needs to be processed and second the address of an integer.

The Function returns the fractional values if the first parameter and stores the remaining whole number in the integer which has been passed to the function.


    X = 10.858 
    Function will return 0.858 
    Function will store the value in the integer = 10

The Function is a part of the math.h library which should be included in the program before using this function.

math.h - modf() function Example in C

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

int main()
	// Defining variables
	double a,b,c;

	// Assigning value for getting modf value
	a = 54.545;

	// Calculating floating-point value into 
	//an integer and a fractional part
	c = modf(a, &b);

	// Displaying the result for the user
	printf("The calculated value is: %lf \n\n", c);

	return 0;


math.h - modf()  in c language

You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions