导入
导出
摘要
保存
撤销
重做
目录
在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;
}