|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
int main()
{
int water;
double money;
scanf("%d",&water);
if(water<=15){
money = (4*water)/3;
}else if(water>15){
money = (2.5*water)-17.5;
}
printf("%.2lf",money);
return 0;
}
本帖最后由 jackz007 于 2021-10-28 22:05 编辑
这一句,这么写是整数除法,会降低计算精度
应该强调是浮点数除法:
下面是我的代码,谨供楼主参考
- #include <stdio.h>
- int main(void)
- {
- double x , y ;
- scanf("%lf" , & x) ;
- if(x > 0.0) {
- if(x <= 15) y = 4.0 * x / 3.0 ;
- else y = x * 2.5 - 17.5 ;
- printf("%.2lf\n" , y) ;
- }
- }
复制代码
编译、运行实况:
- D:\00.Excise\C>g++ -o x x.c
- D:\00.Excise\C>x
- 12
- 16.00
- D:\00.Excise\C>x
- 16
- 22.50
- D:\00.Excise\C>
复制代码
|
|