this question has answer here:
#include<stdio.h> #include<math.h> int main() { float = 2.5; printf("%d, %f", floor(i), ceil(i)); return 0; } although have used %f specifier in printf() ceil, prints 0.000000. why so?
the return type of floor floating point number (double in case). passing "%d" yields undefined behaviour.
you need use %f format specifier. example,
#include <stdio.h> #include<math.h> int main() { float = 2.5; printf("%f, %f", floor(i), ceil(i)); return 0; } output
2.000000, 3.000000
Comments
Post a Comment