C floor() function
C floor() function - Find Integer
Syntax:
double floor(double x)
The floor() function is used to calculate the largest integer that is less than or equal to x.
Parameters:
Name | Description | Required /Optional |
---|---|---|
x | Floating-point value. | Required |
Return value from floor() function
- Returns the floating-point result as a double value.
Example: floor() function
The following example shows the usage of floor() function.
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y;
x = 4.6;
y = -4.6;
printf("Before applying floor()");
printf("\nx = %lf", x);
printf("\ny = %lf", y);
x = floor(x);
y = floor(y);
printf("\n\nAfter applying floor()");
printf("\nx = %lf", x);
printf("\ny = %lf", y);
}
Output:
Before applying floor() x = 4.600000 y = -4.600000 After applying floor() x = 4.000000 y = -5.000000
C Programming Code Editor:
Previous C Programming: C fabs()
Next C Programming: C fmod()
C Programming: Tips of the Day
What's the point of const pointers?
const is a tool which you should use in pursuit of a very important C++ concept:
Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.
Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:
void foo(int* ptr) { ptr = 0;// oops, I meant *ptr = 0 }
If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.
Ref : https://bit.ly/33Cdn3Q
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises