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....
🌐
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.
People also ask

What is the ceil() function in C?
The ceil() function in C is a math function used to round any floating-point number up to the nearest integer. It is available in the math.h library and returns a double value.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
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
🌐
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.
🌐
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.
🌐
Cppreference
en.cppreference.com › w › c › numeric › math › ceil
ceil, ceilf, ceill - cppreference.com
May 23, 2024 - Common mathematical functions · [edit] 1-3) Computes the smallest integer value not less than arg. 4) Type-generic macro: If arg has type long double, ceill is called. Otherwise, if arg has integer type or the type double, ceil is called. Otherwise, ceilf is called.
Find elsewhere
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › ceil function in c
Ceil() Function in C: Syntax, Usage & Examples
April 23, 2025 - 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
July 9, 2025 - double ceil( double x ); float ... C11 or later ... The ceil functions return a floating-point value that represents the smallest integer that is greater than or equal to x....
🌐
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).
🌐
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?

🌐
Wikipedia
en.wikipedia.org › wiki › Floor_and_ceiling_functions
Floor and ceiling functions - Wikipedia
February 5, 2026 - Many programming languages (including C, C++, C#, Java, Julia, PHP, R, and Python) provide standard functions for floor and ceiling, usually called floor and ceil, or less commonly ceiling. The language APL uses ⌊x for floor. The J Programming Language, a follow-on to APL that is designed to use standard keyboard symbols, uses <. for floor and >. for ceiling.
🌐
Codecademy
codecademy.com › docs › c# › math functions › .ceiling()
C# (C Sharp) | Math Functions | .Ceiling() | Codecademy
March 31, 2023 - Math.Ceiling() is a class method that always rounds up to the next full integer.
🌐
IncludeHelp
includehelp.com › c-programs › c-basic-programs-to-demonstrate-example-of-floor-and-ceil-functions.aspx
C program to demonstrate example of floor() and ceil() functions
Both functions are library functions and declare in math.h header file. /* C program to demonstrate example of floor and ceil functions.*/ #include <stdio.h> #include <math.h> int main() { float val; float fVal,cVal; printf("Enter a float value: "); scanf("%f",&val); fVal=floor(val); cVal =ceil(val); printf("floor value:%f \nceil value:%f\n",fVal,cVal); return 0; }
🌐
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).
🌐
The Open Group
pubs.opengroup.org › onlinepubs › 009695199 › functions › ceil.html
ceil
This volume of IEEE Std 1003.1-2001 defers to the ISO C standard. These functions shall compute the smallest integral value not less than x.
🌐
Oreate AI
oreateai.com › blog › implementing-the-ceil-function-in-c-language › 79641306d89e39ba4fc768461e7138eb
Implementing the Ceil Function in C Language - Oreate AI Blog
December 22, 2025 - The ceil() function is a commonly used tool in mathematical calculations within C programming. Its purpose is to round up a floating-point number to the nearest integer. If there is any decimal part present, it pushes the value of that number ...
🌐
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.