Facebook Page Twitter Page LinkedIn Page
× C Standard Library


The C <math.h> fmax() function returns maximum number between the two arguments. If one of the arguments is NaN, then the other argument is returned.

Syntax

double fmax (double x, double y);
float fmaxf (float x, float y);
long double fmaxl (long double x, long double y);

Parameters

x Specify value to compare.
y Specify value to compare.

Return Value

Returns the numerically maximum value.

Example:

In the below example, fmax() function is used to find out the maximum value between the two arguments.

#include <stdio.h>
#include <math.h>
 
int main (){
  printf("%.1lf\n", fmax(50, 100));
  printf("%.1lf\n", fmax(5.5, 10.5));
  printf("%.1lf\n", fmax(-2, 2)); 
  printf("%.1lf\n", fmax(-3, -2));  
  return 0;
}

The output of the above code will be:

100.0
10.5
2.0
-2.0

❮ C <math.h> Library