fmod function(Floating Modulus) in C Language – example and detail

In the C Programming Language, the fmod characteristic returns the remainder when x is divided by means of y.

Syntax

The syntax for the fmod function in the C Language is:

double fmod(double x, double y);

x is divided by y.

Returns

The fmod function returns the the rest when x is divided via y.

Required Header

In the C Language, the required header for the fmod function is:

#include <math.h>

Applies To

In the C Language, the fmod characteristic can be used in the following versions:

ANSI/ISO 9899-1990

fmod Example

/* Example using fmod by TechOnTheNet.com */

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

int main(int argc, const char * argv[])
{
    /* Define temporary variables */
    double value1, value2;
    double result;

    /* Assign the values we will find the fmod of */
    value1 = 1.6;
    value2 = 1.2;

    /* Calculate the remainder of value1 / value2 */
    result = fmod(value1, value2);

    /* Display the result of the calculation */
    printf("The fmod of %f and %f is %f\n", value1, value2, result);

    return 0;
}

When compiled and run, this software will output:

The fmod of 1.600000 and 1.200000 is 0.400000

Similar Functions

Other C features that are comparable to the fmod function:

div function <stdlib.h>

ldiv function <stdlib.h>