×

How to use floor() function in C

Introduction: The floor() used as a function in the C programming language. This function uses to return the largest or most significant integer value. The integer value is smaller than the x or equal to the x.

The floor() function calculates some value, which is known as the nearest integer value. The floor function used the float variable as an argument. This function also computes floor value.

Floor() is a library function in C language.

Syntax of the floor() function in C language:

Syntax means the order or arrangement. The syntax is also known as the function prototype. Every function has a syntax value. The syntax of the floor() function is:

double floor (double x);

In the floor() function, the parameter type is double, and the return type is double. In the C language, the floor() function [double floor (double x)] returns the most significant integer value, which is less than or equal to the x.

Parameters of the floor() function in C language :

In the C language, x uses as a parameter. X is also known as the floating-point value. It is the value which is round down to the nearest integer.

Returns Value of the floor() function in C language:

The floor() function returns the largest or more significant integer value, which is less than x or equal to the x. That means the integer value is not greater than x.

Header file of the floor() function in C language :

Every program contains some header files. For run of the any program, a header file must be needed. Without a header file, you can't run any programs. So, we must produce the header file in every program. It is a file with an extension. The floor() function does not takes a double argument.

The primary use of the header file is to propagate the declaration of code files. The floor() function is one of the most used mathematical functions. The header file of the floor function in C language is <math.h>. This function takes a double value as an argument and returns the value.

It is written in the program as #include <math.h>.

In the C programming language, the floor() function is used in the following version, that is: ANSI/ISO 9899-1990

Example 1

Here we given a example of the floor() function using C language:

#include <stdio.h>
#include <math.h>
int main ()
{
//define temporary variable
double number = 5.55
int result;
result = floor (number)
//display the result
printf (“The floor integer value of %.2f = %d ”, number, result);
return 0;
}

Output: We are compiling and run the above program.The result of this above program is:

The floor integer value of 5.55 = 6

To better understand, we give another two examples of flood() functions.

Example 2

Here we given a example of the floor() function using C language:

#include <stdio.h>
#include <math.h>
int main ()
{
Float val1, val2, val3, val4, val5, val6;
//initialize the values
 val1 = 1.5;
val2 = 2.5;
val3 = 3.5;
val4 = 4.5;
val5 = 5.5;
val6 = 6.6;
//display the results
printf (“Value1 = 1Lf\n”, floor (val1));
printf (“Value2 = 1Lf\n”, floor (val2));
printf (“Value3 = 1Lf\n”, floor (val3));
printf (“Value4 = 1Lf\n”, floor (val4));
printf (“Value5 = 1Lf\n”, floor (val5));
printf (“Value6 = 1Lf\n”, floor (val6));
return 0;
}

Output: We are compiling and running the above program. The result of this above program is:

Value1 = 1.0
Value2 = 2.0
Value3 = 3.0
Value4 = 4.0
Value5 = 5.0
Value6 = 6.0

Example 2

Here we given a example of the floor() function using C language:

#include <stdio.h>
#include <math.h>
int main ()
int (const char * argv[]);
int  argc;
{
// define variables which is temporary
double value;
double result;
Value = 5.5;
//calculate the value of floor
Result = floor (value);
//Display the result
printf (“The floor integer value of %.2f = %d ”, value, result);
return 0;
}

Output: We are compiling and running the above program. The result of this above program is:

The floor integer value of 5.5 = 5.00

In the above three programs, we have used the floor function; through the programs, we briefly discussed how to write any C language program using floor() function.

The floor() function is a mathematical function. That’s why we use the header file <math.h>. We are also share the output of the above three programs.


Related Topics

Pascal Triangle in C

The pascal triangle in c is an array of binomial coefficients in triangular form. Here the nth row contains the binomial coefficient of ncr.In a pascal triangle, every number is...

2 minutes read.

#include in C

In the C programming language, #include is another way of inferring a standard, or a user defines file into the application or program. The preprocessor of the programming standard generally...

4 minutes read.

How to use atoi() function in C

Introduction: The atoi() is a function used in C programming language. This function converts string characters to the integer value. The atoi() function converts the input string to the return type of...

4 minutes read.

Macros in C

In the C programming language, the macro is defined as a segment of the code replaced by the macro defined value at the beginning. ‘#define’ is the directive that defines...

3 minutes read.

Goto and Labels in C

Introduction Goto in C: The goto statement is known as the jump statement in C. The goto is used to transfer the control of a program to a predefined label. The goto...

3 minutes read.

C –Structure

C structure is a collection of different types of data that is grouped together. It is used to represent records.Structkeyword is used to create a structure. Each element of a...

1 minute read.

GCD program of two numbers in C

GCD stands for Greatest Common Divisor, which is also known as Highest Common Factor, which can be abbreviated as HCF. Mathematically it can be defined as any two positive integers...

3 minutes read.

Length of an Array Function in C

In C, there is no built-in function to get the length of an array. However, there are a few ways you can determine the length of an array. It is necessary...

15 minutes read.

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

File Operations in C

Why do I need the file? All data will be lost when the program exits. Saving data to a file keeps it safe even if the program stops working. If there...

6 minutes read.

C Decision control statement

Decision Making C conditional statements are used to specify one or more conditions. The statements will be executed if the condition becomes true otherwise alternative statement will be executed if the...

3 minutes read.

C Program Swap Numbers in cyclic order Using Call by Reference

The three integers that the user entered in cyclical sequence are swapped in this tutorial using call by reference. C Program: #include <stdio.h> void cyclic_Swap ( int *X, int *Y, int *Z ); int...

2 minutes read.

Two-Dimensional array in C

What is an Array? The collection of a fixed number of elements of homogeneous data types that are stored in contiguous locations in the memory is known as an array. Only...

6 minutes read.

How to convert a string to hexadecimal in C

Converting a character array or any string to its respective hexadecimal form is simple. The only thing we have to do is to follow the below steps. Take each character from...

3 minutes read.

Difference between while and for loop in C

While Loop The syntax that can be used for the ‘while’ loop in the C programming language is mentioned below: while (test expression or termination condition)  {   // the main body of the...

6 minutes read.

Results of Comparison Operations in C and C++

In this tutorial, we will explore comparison operators and how the system should compare an incoming value supplied as a context parameter to a given value or range of values. A...

2 minutes read.

Nested Loops in C Programming Examples

A nested loop is generally used when we want to run a loop statement inside another loop statement. This kind of loop is also known as a “loop inside the...

6 minutes read.

Limitations of Synchronisation and Uses of Static Synchronisation in Multithreading

The multithreading component of java is the element around which the idea rotates as it permits simultaneous execution of at least two program pieces for the most significant usage of...

9 minutes read.

Ceil and Floor in C

In arithmetic, a rational number is a number that can be expressed as the quotient p/q of two integers. Where q is zero. The set of rational numbers includes all...

6 minutes read.

Flow Chart of Do while loop in C

This is a flowchart that represents the process of executing the Do while loop in the C programming language Generally, as we know there are three main components of Do While...

3 minutes read.