
//Author : pandaiidayo
#include<stdio.h>
int main()
{
printf("Please enter your water consumption x =");
float x = 0.0;
float y = 0.0;
scanf("%f", &x);
/*
x > 15 -> y = 2.5 * x - 10.5
x <= 15 -> y =4 * x / 3
*/
if(x<= 15){
y =4 * x / 3;
}
else{
y = 2.5 * x - 10.5;
}
printf("Your water charge this month is y = f(%f )= %.2f", x, y);
//y = f(x)
return 0;
}
*巩固了if else语句的使用
这篇博客通过实例探讨了如何使用C语言实现水费计算,重点在于运用if else语句进行条件判断。
1726

被折叠的 条评论
为什么被折叠?



