T1042 分段函数

#include<iostream>
using namespace std;
int main()
{
    float x,result;
    cin>>x;
    if(x>=0.0&&x<5.0)
    {
        result=2.5-x;
        printf("%.3f",result);
    }
    else if(x>=5.0&&x<10.0)
    {
        result=2.0-1.5*(x-3)*(x-3);
        printf("%.3f",result);
    }
    else if(x>=10.0&&x<20.0)
    {
        result=x/2.0-1.5;
        printf("%.3f",result);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_29488513/article/details/89053590