How to use floor() function in C
Introduction: The floor() used as a function in the C programming language. This function uses to return the largest or most significant integer value. The integer value is smaller than the x or equal to the x.
The floor() function calculates some value, which is known as the nearest integer value. The floor function used the float variable as an argument. This function also computes floor value.
Floor() is a library function in C language.
Syntax of the floor() function in C language:
Syntax means the order or arrangement. The syntax is also known as the function prototype. Every function has a syntax value. The syntax of the floor() function is:
double floor (double x);
In the floor() function, the parameter type is double, and the return type is double. In the C language, the floor() function [double floor (double x)] returns the most significant integer value, which is less than or equal to the x.
Parameters of the floor() function in C language :
In the C language, x uses as a parameter. X is also known as the floating-point value. It is the value which is round down to the nearest integer.
Returns Value of the floor() function in C language:
The floor() function returns the largest or more significant integer value, which is less than x or equal to the x. That means the integer value is not greater than x.
Header file of the floor() function in C language :
Every program contains some header files. For run of the any program, a header file must be needed. Without a header file, you can't run any programs. So, we must produce the header file in every program. It is a file with an extension. The floor() function does not takes a double argument.
The primary use of the header file is to propagate the declaration of code files. The floor() function is one of the most used mathematical functions. The header file of the floor function in C language is <math.h>. This function takes a double value as an argument and returns the value.
It is written in the program as #include <math.h>.
In the C programming language, the floor() function is used in the following version, that is: ANSI/ISO 9899-1990
Example 1 –
Here we given a example of the floor() function using C language:
#include <stdio.h>
#include <math.h>
int main ()
{
//define temporary variable
double number = 5.55
int result;
result = floor (number)
//display the result
printf (“The floor integer value of %.2f = %d ”, number, result);
return 0;
}
Output: We are compiling and run the above program.The result of this above program is:
The floor integer value of 5.55 = 6
To better understand, we give another two examples of flood() functions.
Example 2 –
Here we given a example of the floor() function using C language:
#include <stdio.h>
#include <math.h>
int main ()
{
Float val1, val2, val3, val4, val5, val6;
//initialize the values
val1 = 1.5;
val2 = 2.5;
val3 = 3.5;
val4 = 4.5;
val5 = 5.5;
val6 = 6.6;
//display the results
printf (“Value1 = 1Lf\n”, floor (val1));
printf (“Value2 = 1Lf\n”, floor (val2));
printf (“Value3 = 1Lf\n”, floor (val3));
printf (“Value4 = 1Lf\n”, floor (val4));
printf (“Value5 = 1Lf\n”, floor (val5));
printf (“Value6 = 1Lf\n”, floor (val6));
return 0;
}
Output: We are compiling and running the above program. The result of this above program is:
Value1 = 1.0
Value2 = 2.0
Value3 = 3.0
Value4 = 4.0
Value5 = 5.0
Value6 = 6.0
Example 2 –
Here we given a example of the floor() function using C language:
#include <stdio.h>
#include <math.h>
int main ()
int (const char * argv[]);
int argc;
{
// define variables which is temporary
double value;
double result;
Value = 5.5;
//calculate the value of floor
Result = floor (value);
//Display the result
printf (“The floor integer value of %.2f = %d ”, value, result);
return 0;
}
Output: We are compiling and running the above program. The result of this above program is:
The floor integer value of 5.5 = 5.00
In the above three programs, we have used the floor function; through the programs, we briefly discussed how to write any C language program using floor() function.
The floor() function is a mathematical function. That’s why we use the header file <math.h>. We are also share the output of the above three programs.