c语言编程分段计算水费

Python011

c语言编程分段计算水费,第1张

#include<stdio.h>

main()

{

float x,y

scanf("%f",&x)

if(x<0.0) y=0

else if(x>=0&&x<=15) y=4*x/3

else if(x>15) y=2.5*x-10.5

printf("%f\n",y)

}

#include <stdio.h> 

int main(void)

{

int looptimes, ri

double x, y 

looptimes=GetInteger()

for(ri = 1ri <= looptimes ri++){ 

x=GetReal()

if ( x<0 )

y=0

else if( x<=15 )

y=4*x/3 

else

y=2.5*x-10.5

printf("f(%.2f) = %.2f\n", x, y) 

}

return 0

}