84分求助

B2047 分段函数

Chen20090918 @ 2023-07-17 15:06:21

不知道哪错了

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double x,b;
    cin>>x;
    if(x>=0&&x<5)b=-1.0*x+2.5;
    else if(x>5&&x<10)b=2.0-1.5*(x-3.0)*(x-3.0);
    else if(x>=10&&x<20)b=x/2.0-1.5;
    printf("%.3lf",b);
    return 0;
}

by SunsetLake @ 2023-07-17 15:07:56

@Chen20090918 第8行少打了一个等号,应该是

x>=5

by XIxii @ 2023-07-17 15:10:12

@Chen20090918 您第二个判断语句中的x>5应该是x>=5


by Chen20090918 @ 2023-07-17 15:12:54

@CW_gjy 谢谢啦


by Chen20090918 @ 2023-07-17 15:13:29

@XIxii 谢谢啦


|