English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and example of C library function floor()

C Standard Library <math.h>

double floor(double x) returns the largest integer less than or equal to x.

C floor() prototype

double floor(double arg)

The floor() function takes a single parameter and returns a value of type double.

It is<math.h>Defined in the header file.

For example:

If you put2.3Passed to floor(), it will return2.

To calculate the floor() of long double or float, you can use the following prototype.

long double floorl(long double arg);
float floorf(float arg);

Example: C floor() function

#include <stdio.h>
#include <math.h>
int main()
{
    float val1, val2, val3, val4;
    val1 = 9.6;
    val2 = 9.2;
    val3 = -5.8;
    val4 = -5.3;
    printf("Floor1 = %.1lf\n", floor(val1));
    printf("Floor2 = %.1lf\n", floor(val2));
    //Note Negative Numbers
    printf("Floor3 = %.1lf\n", floor(val3));
    printf("Floor4 = %.1lf\n", floor(val4));
    return(0);
}

Output Result

Floor1 = 9.0
Floor2 = 9.0
Floor3 = -6.0
Floor4 = -6.0

C Standard Library <math.h>