×

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

Floor() Function in C

Floor() function is a built-in function in C which is defined in the math.h header file. This function is used to return the nearest integer value which is less than...

4 minutes read.

Pyramid Pattern in C

Pyramid Pattern in C A pyramid is a polyhedron created by connecting a base that will be a polygon, and all the lateral faces are triangles. All the bases are connected...

5 minutes read.

Range of int in C

In this session we know about the rage of the int in C language with the suitable examples and the programs. Firstly, we can learn the range of int: The int is...

3 minutes read.

Header files in C

Header files in C In the C programming language, header files are present, which have an extension of ‘.h’, and it consists of macro definitions, declarations, and so on that are...

4 minutes read.

Banker’s Algorithm in C

Introduction Before doing a "s-state" check to look for potential activities and deciding if allocation should be allowed to continue, the banker's algorithm, a resource allocation and deadlock avoidance algorithm, tests...

5 minutes read.

7 Best IDEs for C/C++ Developers in 2024

As we all know that in programming languages, C is known as the building block which cannot be contradicted, and C++ is the prolong kind of C and it can...

4 minutes read.

Caesar Cipher Program in C

What is Caesar Cipher? The Caesar Cipher is a type of substitution cipher that is named after Julius Caesar, who is said to have used it to encrypt messages sent to...

2 minutes read.

Pi() Function in C

Pi: Mathematic constants are not defined in the c or c++ programming languages. To use the Mathematical constants firstly, we have to define the _USE_MATH_DEFINES and then declare the cmath and...

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.

Types of Function in C

A function is a piece of code that accomplish a certain operation for a specific task. There are two types of functions in C: System-defined function (Library Function)User-defined function 1. System defined Function...

8 minutes read.

GPA Calculator in C

GPA stands for Grade Point Average. This GPA is used to measure the student's academic performance in educational institutes. By using this, segregation takes place and lets us know how...

4 minutes read.

Use of free() function in C

Introduction The free() function uses in C programming language. The free() function in the C programming language uses to release or deallocate the memory blocks; these blocks are previously allocated by calloc(), malloc() or realloc()...

3 minutes read.

Sum of N numbers in C using For loop

Before we move on the program of sum of N numbers, first we have to know about the For Loop statement. The syntax of ‘for’ loop in C programming language is...

3 minutes read.

Find reverse of an array in C using functions

Introduction: Here, we describe how to find the reverse array in C using functions. Suppose you have an array with n elements. I need to display the elements present in...

3 minutes read.

Find a subarray with a given sum.

Find a subarray with a given sum. The simple solution is to recognize all subarrays one by one and to check each subarray's sum. The quick solution follows the following program. Algorithm: From...

4 minutes read.

Write() function in c

As the name suggests the write () function is used to write the file descriptor. In other words it is used to write any file name without specifying file name,...

3 minutes read.

#error #pragma in C

#error, #pragma in C #error, also known as the error directive in the C language. It will not allow you to make any compilation fail and immediately issues a statement which...

4 minutes read.

C Program to Find the Largest Number using Ternary Operator

In this tutorial, we will write some program to determine which of the provided integers is larger using the ternary operator, also known as the conditional operator in C. Ternary Operator: The ternary...

3 minutes read.

C Program to find the size of a File

Before knowing about the Program, you need to understand what the size of a file is. After that, you should know how it is going to work with the given...

4 minutes read.

If else Programs in C Programming

If else Programs in C programming The if-else statement in C is based on some particular conditions to perform the operations. If and only if the given condition is valid, the operations listed in...

4 minutes read.