Try this out:

#define CEILING_POS(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X))
#define CEILING_NEG(X) (int)(X)
#define CEILING(X) ( ((X) > 0) ? CEILING_POS(X) : CEILING_NEG(X) )

Check out the link for comments, proof and discussion: http://www.linuxquestions.org/questions/programming-9/ceiling-function-c-programming-637404/

Thanks to Vilhelm Gray and carveone for pointing out that the linked definition of CEILING_NEG(X) is incorrect.

Answer from nintendo on Stack Overflow
🌐
W3Schools
w3schools.com › c › ref_math_ceil.php
C Math ceil() Function
C Examples C Real-Life Examples ... printf("%f", ceil(-5.9)); Try it Yourself » · The ceil() function rounds a number UP to the nearest integer....
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-ceil-function
C ceil() Function - GeeksforGeeks
July 7, 2024 - C ceil() is a built-in library function that computes the smallest integer value greater than or equal to the given floating-point number.
People also ask

What are the alternatives to ceil() function in C?
Alternatives include floor() for rounding down and round() for the nearest integer. You can also use manual logic, but using built-in functions like ceil() is safer and more readable in C.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
What is the return value of ceil() in C?
The ceil() function in C always returns a result as a double, even if the output looks like an integer. This ensures accuracy and prevents overflow with large floating-point inputs.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
What is the ceil value?
The ceil() function calculates the next highest whole number greater than or equal to x.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
🌐
Programiz
programiz.com › c-programming › library-function › math.h › ceil
C ceil() - C Standard Library
The ceil() function computes the nearest integer greater than the argument passed.
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › c_function_ceil.htm
C library - ceil() function
The C library ceil() function of type double accept the single argument(x) that returns the smallest integer value greater than or equal to, by the given value. This method rounded up the nearest integer.
🌐
Cppreference
en.cppreference.com › w › c › numeric › math › ceil
ceil, ceilf, ceill - cppreference.com
#include <math.h> #include <stdio.h> int main(void) { printf("ceil(+2.4) = %+.1f\n", ceil(2.4)); printf("ceil(-2.4) = %+.1f\n", ceil(-2.4)); printf("ceil(-0.0) = %+.1f\n", ceil(-0.0)); printf("ceil(-Inf) = %+f\n", ceil(-INFINITY)); }
🌐
TechOnTheNet
techonthenet.com › c_language › standard_library_functions › math_h › ceil.php
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).
Find elsewhere
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
January 4, 2026 - Here’s a concise answer. The ceil() function in C is a mathematical function used to round a floating-point number up to the nearest integer that is greater than or equal to the given value.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › ceil-ceilf-ceill
ceil, ceilf, ceill | Microsoft Learn
... Calculates the ceiling of a ... C11 or later ... The ceil functions return a floating-point value that represents the smallest integer that is greater than or equal to x....
🌐
The Open Group
pubs.opengroup.org › onlinepubs › 009695199 › functions › ceil.html
ceil
An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred. Upon successful completion, ceil(), ceilf(), and ceill() shall return the smallest integral value not less than x, expressed as a type double, float, or long double, respectively.
🌐
Scaler
scaler.com › topics › ceil-function-in-c
Ceil Function in C - Scaler Topics
April 20, 2022 - The ceil() function in C is declared in the math.h header file is used to find a nearest integral value that is not less than the given number(provided as a parameter to the function).
🌐
Reddit
reddit.com › r/learnprogramming › writing a ceiling function in c
r/learnprogramming on Reddit: Writing a ceiling function in C
September 18, 2013 -

I'm trying to write a function that (kind of) emulates the ceiling function in the math library, in a way that is more useful for my purposes. The code I've written is not working as expected. It should take two integer arguments, divide one by the other, and round up to the nearest integer no matter what the result is.

Ex: 2/2=1 --> answer is 1; 10/3=3.333... --> round up to 4.

This is my code:

int ceiling(int number, int value){
    float a = number/value;
    int b = number/value;
    float c = a - b;
    if(c!=0){
        b=b+1;
    }
    return b;
}

Using the examples above,

ceiling(2,2); would return 1, as expected.

ceiling(10,3); returns 3, when it should return 4.

My thought process is that if a is a float, then 10/3 should be 3.33333..., and if b is an int, then 10/3 should be 3. If c is a float, a-b should be 0.33333..., then since c!=0, ceiling should increment b and return that value. Where am I going wrong?

🌐
Tutorial Gateway
tutorialgateway.org › c-ceil-function
C ceil Function
April 2, 2025 - C ceil function is one of the Math Functions that returns the smallest integer that is greater than or equal to a given number or expression.
🌐
Programming Simplified
programmingsimplified.com › c › math.h › ceil
ceil in C - math.h | Programming Simplified
Home » C programming » math.h » ceil in C - math.h · Ceil function is used to round up a number i.e. it returns the smallest number which is greater than argument passed to it.
🌐
Quora
quora.com › What-is-the-use-of-ceil-in-C-with-examples
What is the use of ceil in C, with examples? - Quora
Answer (1 of 5): 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).
🌐
Fresh2Refresh
fresh2refresh.com › home › c programming tutorial › c – arithmetic functions › c – ceil() function
C ceil() function | C Arithmetic functions | Fresh2Refresh
September 23, 2020 - C ceil() function:ceil( ) function in C returns nearest integer value which is greater than or equal to the argument passed to this function.
🌐
Codelessons
codelessons.dev › en › ceil-in-c-cplusplus
ceil in C/C++: rounding up
The ceil function in C and C++ rounds a number up. This article explores how to use it with examples, and even how to implement it. We'll also differentiate between `ceil`, `ceill`, and `ceilf`. There are exercises at the end for reinforcement.