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.
Discussions

Implementation of ceil function in C - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I have two questions regarding ceil() function.. More on stackoverflow.com
🌐 stackoverflow.com
Writing a ceiling function in C
The variables number and value are both ints. Therefore the expression number/value is integer division: it is the division of two int values. This is integer division, and it returns an integer value, regardless of whether you subsequently decide to store that integer value in a float variable or an int variable. To get floating-point division, you need to cast at least one of the two variables number and value to float before you do the division. For example, float a = (float)number / value; Here, number is cast to a float before the division. Because one of the operands of the division is a floating-point value now, the division is floating-point division, not integer division. === For what it's worth, why aren't you just doing this? #include int ceiling(int number, int value) { return ceil((float)number / value); } More on reddit.com
🌐 r/learnprogramming
4
5
September 18, 2013
In C, is it possible to emulate the ceil() function without utilizing ceil() nor if and else statements?
Why? https://en.cppreference.com/w/c/numeric/math/ceil There's a sample implementation there More on reddit.com
🌐 r/programminghelp
6
3
December 12, 2020
How to return the ceiling of a number without using ceil() function?
double ceil(double a) { auto b = double((long long)a); if (a < 0 || b == a) { return b; } else { return b+1; } } EDIT: fixed negative number behavior and casted to larger to integral type per u/bad_investor13 More on reddit.com
🌐 r/cpp_questions
22
5
September 12, 2023
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 Standard 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
May 23, 2024 - #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)); }
Find elsewhere
🌐
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).
🌐
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.
🌐
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.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › ceil-ceilf-ceill
ceil, ceilf, ceill | Microsoft Learn
July 9, 2025 - ... 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....
🌐
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
December 9, 2022 - 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
May 26, 2023 - 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.
🌐
CodeToFun
codetofun.com › c › math-ceil
C ceil() Function | CodeToFun
April 23, 2025 - The ceil() function is a standard library function in C that is used to round a specified floating-point number up to the nearest integer greater than or equal to the given value.
🌐
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.