C++ Math modf()

This function is used to divide a number into integral and fractional part.

For example :

Syntax

Suppose a number is 'x' and 'ptr' is the pointer to an integral part.

Parameter

x: The value which is to be broken into two parts i.e(fractional and integral part).

ptr: It is the pointer to an object where the integral part of x is stored.

Return value

It returns the integral part of x.

Example 1

Let's see a simple example

Output:

Value of x is : 18.26
integral part of x is :18
fractional part of x is :0.26

In this example, modf() function breaks a number into fractional and integral part. Fractional part is 0.26 and integral part is 18.

Example 2

Let's see a simple example when the value of x is negative.

Output:

Value of x is : -78.34
integral part of x is :-78
fractional part of x is :-0.339996





Latest Courses