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()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming/math/c-floor.php