zhanghr12 @ 2024-01-11 21:11:50
#include<bits/stdc++.h>
using namespace std;
int main()
{
float x,y;
cin>>x;
if(x<=0 && x<5) y=x+2.5;
if(x<=5 && x<10) y=1.5*(x-3)*(x-3);
if(x<=10 && x<20) y=x/2-1.5;
printf("%0.3f", y);
return 0;
}
by qingchenMC @ 2024-01-11 21:31:08
#include<bits/stdc++.h>
using namespace std;
int main(){
float x,y=0;
cin>>x;
if(x>=0 && x<5)y=-x+2.5;
else if(x>=5 && x<10)y=2-1.5*(x-3)*(x-3);
else if(x>=10 && x<20)y=x/2-1.5;
printf("%0.3f",y);
return 0;
}
主要是大于等于号写反了,还有式子抄错了一部分,建议养成仔细读题的习惯,把自己的代码和原题仔细对照避免抄错。
by zhanghr12 @ 2024-01-12 22:14:25
感谢dalao调试!!! O(∩_∩)O
by ZX_XYZ @ 2024-01-20 11:15:25
x=float(input()) if 0<=x<5: y=-x+2.5 if 5<=x<10: y=2-1.5(x-3)(x-3) if 10<=x<20: y=x/2-1.5 print(f"{y:.3f}")