导入
导出
摘要
保存
撤销
重做
目录
在C语言中有涉及除法的取整问题,一般分为向上取整和向下取整;
向上取整可以用ceil()函数实现;
向下取整可以用floor()函数实现;
两个的头文件都是math.h ;
#include <stdio.h>
#include <math.h>
int main()
{
int t;
int a, b, asw;
float c;
scanf("%d%d%d",&t,&a,&b);// t用来判断除法类型的;
if(t == 1)
{
c = a * 1.0 / b * 1.0;
asw = floor(c);
}
else
{
c = a * 1.0 / b * 1.0;
asw = ceil(c);
}
printf("%d\n",asw);
return 0;
}
本文介绍C语言中处理除法取整的方法,包括向上取整(使用ceil()函数)和向下取整(使用floor()函数),并提供了一个示例代码,展示了如何根据不同的需求选择合适的取整方式。
4261





