Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ceiling function
#include <stdio.h>
double my_ceil(double x) {
double y = (double) ((long long) x);
if (x - y == 0) {
return x;
} else {
if (x > 0) {
return y + 1;
} else {
return y;
}
}
}
int main(void) {
printf ("ceil of 2.0 is %.1lf\n", my_ceil(2.0) );
printf ("ceil of 3.8 is %.1lf\n", my_ceil(3.8) );
printf ("ceil of -2.3 is %.1lf\n", my_ceil(-2.3) );
printf ("ceil of -3.0 is %.1lf\n", my_ceil(-3.0) );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment