Library Function ceil in Math Class

Library Function ceil of math.h Header File in C

On this page we will discuss about library function ceil in math class which is used in C.
The C header file math.h contains the standard math library functions that can be used for performing various mathematical operations. The ceil function returns the nearest greater integer than the argument passed.

Library Function cbrt in Math Class

Library Function ceil of math.h Header File

In C programming language the ceil function is included in math.h header file.

The range of input argument which is passed to ceil function is not limited here as it can be any value from int to float or double but then has to be type casted into double type.

Declaration of ceil function

double ceil(double x) 

Parameters of ceil function

The ceil function accepts a single input argument  which is a double value.

ParameterDescription
double valueThis value of double function ranges from all positive and negative numbers.

Return value of ceil function

The ceil function returns a nearest integer value greater than the argument passed and it’s type is double.

ParameterReturn Value
Nearest Integer greater than argument It returns the value of int type.

Implementation of Library Function math.h ceil

Example 1:

The following code shows the use of ceil function.

Run
#include<stdio.h>
#include<conio.h>
int main()
{
   double num = 8.33;
   int result;
   result = ceil(num);
   printf("Ceiling integer of %.2f = %d", num, result);
   return 0;
}

Output:

Ceiling integer of 8.33 = 9

Example 2:

Run
#include<stdio.h>
#include<conio.h> 
int main () 
{
   float val1, val2, val3, val4;
   val1 = 1.6;
   val2 = 1.2;
   val3 = 2.8;
   val4 = 2.3;
   printf ("value1 = %.1lf\n", ceil(val1));
   printf ("value2 = %.1lf\n", ceil(val2));
   printf ("value3 = %.1lf\n", ceil(val3));
   printf ("value4 = %.1lf\n", ceil(val4));
   return 0;
}

Output:

value1 = 2.0
value2 = 2.0
value3 = 3.0
value4 = 3.0

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription