Library Function floor in Math Class

Library Function floor of math.h Header File in C

In this section, we will discuss about library function fabs in math class which is used in C.The C header file math.h contains the standard math library functions that can be used for performing various mathematical operations. The fabs function returns the nearest integer of the argument passed.

library function floor in math class

Library Function floor of math.h Header File

  • In C programming language the floor function is included in math.h header file.
  • The range of input argument which is passed to floor function is not limited here as it can be any value such as float or long double also.

Declaration of floor function

double floor(double arg) 

Parameters of floor function

The floor function accepts a single input argument  which can be a double/float or long double value.

Parameter        Description
double or float or long doubleThis value of double function ranges to all positive and negative     numbers.

Return value of floor function

The floor function returns the nearest integer value of the argument passed.

ParameterReturn Value
Nearest Integer of the argument passedIt returns the value in double/float/long double.

Implementation of Library Function math.h floor()

Example 1:

The following code shows the use of floor function.

Run

#include<stdio.h> 
#include<math.h> 
int main() {

   double num = -8.33;

   double result = floor(num);

   printf("Floor integer of %.2f = %.0f", num, result);
   return 0;
}

Output:

Floor integer of -8.33 = -9

Example 2:

Run

#include<stdio.h> 
#include<math.h> 
int main () {
   float val1, val2;

   val1 = 1.6;
   val2 = 1.2;
   printf("Value1 = %.1lf\n", floor(val1));
   printf("Value2 = %.1lf\n", floor(val2));   
   return(0);
}

Output:

Value1 = 1.0
Value2 = 1.0

 

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription