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 11, 2020
ceil() function is not working
Without looking at your code, I presume you may need to link the math library while compiling your program. Something like this may work- gcc stuff.c -o stuff -lm More on reddit.com
🌐 r/C_Programming
17
January 6, 2022
🌐
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.
🌐
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 - 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
🌐
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....
🌐
Linux Man Pages
man7.org › linux › man-pages › man3 › ceil.3.html
ceil(3) - Linux manual page
#include <math.h> double ceil(double ... */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE · These functions return the smallest integral value that is not less than x....
🌐
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.
🌐
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
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.
🌐
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).
🌐
Cplusplus
cplusplus.com › reference › cmath › ceil
Ceil
double ceil (double x); float ceil (float x);long double ceil (long double x); double ceil (T x); // additional overloads for integral types ... Rounds x upward, returning the smallest integral value that is not less than x. Header <tgmath.h> provides a type-generic macro version of this function.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › ceil-floor-functions-cpp
Ceil and Floor functions in C++ - GeeksforGeeks
May 16, 2025 - #include <iostream> #include <cmath> ... return 0; } ... ceil() function in C++ returns the smallest integer that is greater than or equal to the value passed as the input argument....
🌐
Cppreference
en.cppreference.com › w › cpp › numeric › math › ceil
std::ceil, std::ceilf, std::ceill - cppreference.com
October 15, 2023 - Common mathematical functions · [edit] 1-3) Computes the least integer value not less than num. The library provides overloads of std::ceil for all cv-unqualified floating-point types as the type of the parameter.(since C++23) If no errors occur, the smallest integer value not less than num, ...
🌐
YouTube
youtube.com › watch
C Programming Tutorial - Ceil and Floor Functions - YouTube
In this #C #Programming #Tutorial I discuss the #ceil and #floor #functions.To view this entire playlist:https://youtube.com/playlist?list=PLwTHcico4iPPdtKal...
Published   January 3, 2022
🌐
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.
🌐
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?