floor - C math.h

C examples for math.h:floor

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Rounds x downward, returning the largest integral value that is not greater than x.

Prototype

long double floorl (long double x);
long double floor (long double x);
     double floor (double x);
      float floorf (float x);
      float floor (float x);
     double floor (T x);           

Parameters

Parameter Description
x Value to round down.

Return Value

The value of x rounded downward (as a floating-point value).

Example

Demo Code


#include <stdio.h>
#include <math.h> /* floor */

int main ()/*from   w  w w  .  j av  a2s.c o  m*/
{
  printf ( "%.1lf\n", floor (2.1) );
  printf ( "%.1lf\n", floor (3.9) );
  printf ( "%.1lf\n", floor (-2.1) );
  printf ( "%.1lf\n", floor (-3.9) );
  return 0;
}

Related Tutorials