|
|
floor() - Mathematical Function
|
Tutorials

Cpp

|
Topic |
How is Mathematical Function "floor()" used in C++?
How to find the round down value of a number?
|
|
Explanation |
|
floor() is a Mathematical Function that returns the largest integer that can be
represented as a floating point value which is not greater then the given number "num". In other words , it returns the Round Down value of a given number.
Syntax:
float floor( float num);
double floor( double num);
long double floor( long double num);
Example:
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("floor of 3.2 is %.1lf\n", floor (3.2) );
printf ("floor of 3.8 is %.1lf\n", floor (3.8) );
printf ("floor of -4.3 is %.1lf\n", floor (-4.3) );
printf ("floor of -7.7 is %.1lf\n", floor (-7.7) );
return 0;
}
|
Result:
floor of 3.2 is 3.0
floor of 3.8 is 3.0
floor of -4.3 is -5.0
floor of -7.7 is -8.0
In the above example floor() function is used to
return the round down value of the number specified.
|
| Note |
C++ is one of the most used programming languages in the world. Also known as "C with Classes".
Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.
|
|
|
|