fmod in c

What is fmod in c programming?

fmod in c is a function is a mathematical function which is used to calculate remainder of two given numbers.

This function is defined in math.h header file.

Prototype

double fmod(double x, double y);

Parameter

This function takes two floating point values as input parameters.

Return value

This function returns the remainder of x/y.


Example program for fmod in c

#include<stdio.h>
#include<math.h>
int main()
{
  double x,y;
  printf("\n\n\tEnter the double type values \n\t");
  scanf("%lf %lf",&x,&y);
  printf("\n\tThe remainder is %lf \n\n",fmod(x,y));
  return 0;
}
Example for fmod in c programming
Output of example for fmod in c programming

While using gcc use below command to add math header.

gcc file_name.c -lm

Code explanation

The remainder of the given input values is found by passing them to the fmod function. The result is being copied on to the console.

fmod() Man page


Difference between fmod and div in c

fmod is a mathematical function that is used to calculate the remainder of two given numbers. div function divides two given numbers.

fmod takes double type values as input parameters. div function takes integers as input parameters.

fmod is defined in math.h header file. div is defined in stdlib.h header file.

Prototypes are as follows

double fmod(double x, double y);

div_t div(int numerator, int denominator);
fmod ( )div ( )
Used to calculate remainder of two given numbers.Divides two given numbers.
double fmod(double x, double y);div_t div(int numerator, int denominator);

People also ask for

What is fmod in c?

fmod is a mathematical function that is used to calculate the remainder of two given numbers. It is defined in math.h header file.