totn C Functions

C Language: ceil function
(Ceiling)

In the C Programming Language, the ceil function returns the smallest integer that is greater than or equal to x (ie: rounds up the nearest integer).

Syntax

The syntax for the ceil function in the C Language is:

double ceil(double x);

Parameters or Arguments

x
The value to round up to the nearest integer.

Returns

The ceil function returns the smallest integer that is greater than or equal to x.

Required Header

In the C Language, the required header for the ceil function is:

#include <math.h>

Applies To

In the C Language, the ceil function can be used in the following versions:

  • ANSI/ISO 9899-1990

ceil Example

/* Example using ceil by TechOnTheNet.com */

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    /* Define temporary variables */
    double value;
    double result;

    /* Assign the value we will find the ceil of */
    value = 1.6;

    /* Calculate the ceil of value */
    result = ceil(value);

    /* Display the result of the calculation */
    printf("The ceil of %f is %f\n", value, result);

    return 0;
}

When compiled and run, this application will output:

The ceil of 1.600000 is 2.000000

Similar Functions

Other C functions that are similar to the ceil function: