C 语言的 ceil 函数是数学函数之一,它返回大于或等于给定数字或表达式的最小整数值。数学 ceil 函数的语法如下所示。
double ceil(double number);
math ceil 函数示例
此数学函数允许您找到大于或等于给定数字的最小整数值。在此程序中,我们将找到其上界值并显示输出。
#include <stdio.h>
#include <math.h>
int main()
{
printf("\n The Ceil Value of 0.75 = %.2f ", ceil(0.75));
printf("\n The Ceil Value of 12.25 = %.2f ", ceil(12.25));
printf("\n The Ceil Value of 152.50 = %.2f ", ceil(152.50));
printf("\n The Ceil Value of -12.36 = %.2f ", ceil(-12.36));
printf("\n The Ceil Value of -27.82 = %.2f ", ceil(-27.32));
printf("\n The Ceil Value of -90.50 = %.2f ", ceil(-90.50));
return 0;
}

math ceil 示例 2
在此 C 编程 示例中,我们允许用户输入自己的值。接下来,程序 使用 math ceil 函数来查找最接近的数字。
#include <stdio.h>
#include <math.h>
int main()
{
float number, ceilValue;
printf(" Please Enter any Numeric : ");
scanf("%f", &number);
ceilValue = ceil(number);
printf("\n The Ceiling of %.2f = %.4f ", number, ceilValue);
return 0;
}
Please Enter any Numeric : 256.09
The Ceiling of 256.09 = 257.0000