Math Floor Function

C++ Math floor

It rounds the value to the nearest integer which is not greater than the given value.

For example:

Example

floor(8.2)=8.0;
floor(-8.8)=-9.0;

Syntax

Suppose a number is 'x'. Syntax would be :

Example

double floor(double x);

Parameter

x : It is the value that rounds to the nearest integer.

Return value

It returns the value that round to the nearest integer not greater than x.

Example 1

Let's see a simple example by considering a positive value.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
 float x=7.8;
 std::cout << "Initial value of x is : " << x<<std::endl;
cout<<"Now, the value of x is :"<<floor(x);
 return 0;
}

Output:

Output

Initial value of x is : 7.8
Now, the value of x is :7

Example 2

Let's see a simple example by considering a negative value.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
 float x=-10.2;
 std::cout << "Initial value of x is : " << x<<std::endl;
cout<<"Now, the value of x is :"<<floor(x);
 return 0;
}

Output:

Output

Initial value of x is : -10.2
Now, the value of x is :-11

Input Required

This code uses input(). Please provide values below: