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
🌐
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.
🌐
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)); }
🌐
W3Schools
w3schools.com β€Ί c β€Ί ref_math_ceil.php
C Math ceil() Function
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... printf("%f", ceil(0.60)); printf("%f", ceil(0.40)); printf("%f", ceil(5)); printf("%f", ceil(5.1)); printf("%f", ceil(-5.1)); printf("%f", ceil(-5.9)); Try it Yourself Β»
🌐
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.
🌐
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
🌐
The Open Group
pubs.opengroup.org β€Ί onlinepubs β€Ί 009695199 β€Ί functions β€Ί ceil.html
ceil
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.
🌐
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.
🌐
Linux Man Pages
man7.org β€Ί linux β€Ί man-pages β€Ί man3 β€Ί ceil.3.html
ceil(3) - Linux manual page
For an explanation of the terms used in this section, see attributes(7). β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Interface β”‚ Attribute β”‚ Value β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ ceil(), ceilf(), ceill() β”‚ Thread safety β”‚ MT-Safe β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Β· C11, POSIX.1-2008.
🌐
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?

🌐
Cplusplus
cplusplus.com β€Ί reference β€Ί cmath β€Ί ceil
Ceil
The smallest integral value that is not less than x (as a floating-point value). ... Home page | Privacy policy Β© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s Spotted an error?
🌐
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.
🌐
Vultr
docs.vultr.com β€Ί clang β€Ί standard-library β€Ί math-h β€Ί ceil
C math.h ceil() - Round Up to Integer | Vultr Docs
September 27, 2024 - It ensures every item has a package, even if the last package is not completely full. The ceil() function in the math.h library is an invaluable tool in C for rounding up floating-point numbers to the nearest integer.
🌐
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).
🌐
O'Reilly
oreilly.com β€Ί library β€Ί view β€Ί c-in-a β€Ί 0596006977 β€Ί re31.html
ceil - C in a Nutshell [Book]
December 16, 2005 - The ceil() function returns the smallest integer that is greater than or equal to its argument. However, the function does not have an integer type; it returns an integer value, but with a floating-point type.
Authors Β  Peter PrinzTony Crawford
Published Β  2005
Pages Β  618