题目:
为鼓励居民节约用水,自来水公司采取按用水量阶梯式计价的办法,居民应交水费y(元)与月用水量x(吨)相关:当x不超过15吨时,y=4x/3;超过后,y=2.5x−17.5。请编写程序实现水费的计算。
输入格式:
输入在一行中给出非负实数x。
输出格式:
在一行输出应交的水费,精确到小数点后2位。
题目解答:
#include<stdio.h>
int main(){
float ton;
scanf("%f",&ton);
if(ton<=15){
printf("%.2f",4*ton/3);
}else{
printf("%.2f",2.5*ton-17.5);
}
return 0;
}