![]() |
In the C language, the <math.h> header file contains the Standard Math Library that provides various mathematical functions, including the ceil() function. In this article, we will see how to use the ceil() function in C. What is ceil() in C?C ceil() is a built-in library function that computes the smallest integer value greater than or equal to the given floating-point number. It is defined inside the <math.h> header file with its prototype as follows: Syntax of ceil()double ceil(double x); Parameters
Return ValueThe ceil() function returns the smallest integer value greater than or equal to the input number as a double. Example of ceil() in CInput: The given below program demonstrates how we can calculate the ceil value of various numbers in C.
Output Number 1: 1.4 Number 2: 1.5 Number 3: -1.5 Number 4: -1.6 Ceiling value of num1: 2.0 Ceiling value of num2: 2.0 Ceiling value of num3: -1.0 Ceiling value of num4: -1.0 How ceil() in C works?The C ceil() function works by rounding a floating-point number up to the smallest integer value that is greater than or equal to the given number. Here’s a breakdown:
ConclusionIn this article, we discussed the C standard library function ceil() which is used to round floating-point numbers up to the nearest integer. The standard library contains useful and frequently used functions that make programming easier by avoiding the need to rewrite common functions repeatedly. Frequently Asked Questions on C ceil() FunctionWhat does the ceil() function return for a positive floating-point number?
Can the ceil() function handle negative numbers?
How does ceil() differ from other rounding functions like floor() and round()?
|
Reffered: https://www.geeksforgeeks.org
C Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 19 |