What is floor in c programming?
floor in c is used to find out integer value less than or equal to the given number.
This function is defined in math.h header file.
Prototype
#include<math.h>
double floor(double m);
Parameters
floor function takes floating point number as parameter.
Return value
floor function returns integer value less than or equal to the given number.
Example program for floor in c
#include <stdio.h>
#include <math.h>
int main()
{
float val1=1.1;
printf("floor value is %lf \n",floor(val1));
return 0;
}
While using gcc use below command to add math header.
gcc file_name.c -lm
Code explanation
The floor function is called by passing input number to it. The result is being printed onto the console.
Difference between floor and abs in c
The floor in c is used to find out nearest integer value which is less than or equal to the given value. abs in c is used to find out the absolute value of a given number.
floor returns positive or negative value which is nearest to that number. abs returns positive value.
floor function is included in math.h header file. abs is included in stdlib.h header file.
Prototypes are as follows
double floor(double y);
int abs(int m);
floor( ) | abs( ) |
Used to find out nearest integer value which is less than or equal to the given value. | Used to find out absolute value of given number. |
double floor(double y); | int abs(int m); |
Difference between floor and ceil in c
The floor in c is used to find out the nearest integer value which is less than or equal to the given value. ceil in c is used to find out the nearest integer value which is greater than or equal to the given number.
Prototypes are as follows
double floor(double y);
double ceil(double y);
floor( ) | ceil( ) |
Used to find out nearest integer value which is less than or equal to the given value. | Used to find out nearest integer value which is greater than or equal to given number. |
double floor(double y); | double ceil(double y); |
People also ask for
What is floor in c?
The floor in c is used to find out the nearest integer value which is less than or equal to the given value. It is defined in math.h header file.