7-23 分段计算居民水费

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main(void)
 4 {
 5     double x, y;
 6 
 7     scanf("%lf", &x);
 8 
 9     /*浮点数比较大小*/
10     if (fabs(x - 15.0) > 1e-6 && x > 15.0)
11     {
12         y = 2.5 * x - 17.5;
13     }
14     else
15     {
16         y = 4 * x / 3;
17     }
18 
19     printf("%.2f", y);
20 
21     return 0;
22 }

猜你喜欢

转载自www.cnblogs.com/2018jason/p/12028088.html