w3resource

C floor() function

C floor() function - Find Integer

Syntax:

double floor(double x)

The floor() function is used to calculate the largest integer that is less than or equal to x.

Parameters:

Name Description Required /Optional
x Floating-point value. Required

Return value from floor() function

  • Returns the floating-point result as a double value.

Example: floor() function

The following example shows the usage of floor() function.


#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double x, y;
   x = 4.6;
   y = -4.6;
   printf("Before applying floor()");
   printf("\nx = %lf", x);
   printf("\ny = %lf", y);    
   x = floor(x);
   y = floor(y);
   printf("\n\nAfter applying floor()");
   printf("\nx = %lf", x);
   printf("\ny = %lf", y);    
}

Output:

Before applying floor()
x = 4.600000
y = -4.600000

After applying floor()
x = 4.000000
y = -5.000000

C Programming Code Editor:

Previous C Programming: C fabs()
Next C Programming: C fmod()



Follow us on Facebook and Twitter for latest update.