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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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?

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....
๐ŸŒ
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).
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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).