floor() in c – floor C Library Function

floor() in c: The function double floor(double x); returning the largest integral value less than or equal to x.

Function prototype of floor

double floor(double x);
  • x : A floating point value to round down.

Return value of floor

Floor function in c: It returns the largest integral value less than or equal to x.

C program using floor function

The following program shows the use of floor function to round down value of x.

floor C Library Function

#include <stdio.h>
#include <math.h>
 
int main ()
{
  double x, result;
  printf("Enter a number\n");
  scanf("%lf", &x);
   
  result = floor(x);
  printf("Largest integer <= of %lf is %lf\n", x, result);
   
  return 0;
}

Output

Enter a number
2.3
Largest integer <= of 2.300000 is 2.000000
Enter a number
-2.3
Largest integer <= of -2.300000 is -3.000000