Ceil Function in CThis section will discuss the Ceil function in the C programming language. Ceil function is a predefined function of math.h header file. It returns the nearest integer number, which is greater than or equal to the number passed as an argument in it. For example, we pass the float number 3.4, and the ceil() function returns the greatest number 4. ![]() SyntaxParametersHere, x is an argument of the ceil function. ReturnsThe ceil() function returns the smallest possible integer value to round up the passed number x. Properties of the ceil function
Note: The ceil() function can only be used with floating-point positive and negative numbers to round off the given number. If the passed positive and negative number is an integer, the function returns the same number without ceiling or round off the nearest given number.Example 1: Program to ceil a number using the ceil() functionOutput The ceiling integer of 9.37 = 10 As shown in the program, the value of variable num 9.37 is passed to the ceil() function returns the round off to its nearest integer value 10. Example 2: Program to ceil the floating number using the ceil() functionOutput The ceiling value of 2.30 is 3.00 The ceiling value of -2.70 is -2.00 The ceiling value of 5.10 is 6.00 The ceiling value of 56.40 is 57.00 The ceiling value of 2.80 is 3.00 Example 3: Program to round up the floating number using the ceil() functionOutput Enter the float number: 55.6 The ceil of 55.60 is 56.000000 Example 4: Program to round up the positive and negative numbers using the ceil() functionOutput Enter the positive integer: 56 Enter the negative integer: -24 The ceiling integer of 56 = 56 The ceiling integer of -24 = -24
Next TopicRelational Operator in C
|