PTA-基础编程题目集-7-11 分段计算居民水费

题目来源:https://pintia.cn/problem-sets/14/problems/791

 

 注意,当x超过15时,y不是4*15/3+2.5*(x-15)-17.5

 

 

 1 #include<stdio.h>
 2 int main(){
 3     float x,y;
 4     scanf("%f",&x);
 5     if(x>=0&&x<=15){
 6         printf("%.2f",4*x/3);
 7     }
 8     if(x>15){
 9         printf("%.2f",x*2.5-17.5);
10     }
11                return 0;
12 }

 

posted @ 2021-03-25 13:23  Listendown  阅读(108)  评论(0)    收藏  举报