84分,求大佬帮下

B2047 分段函数

IKUN54088DS @ 2024-02-15 12:36:35

B2047


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

by wangruiqi36 @ 2024-02-15 12:48:22

@IKUN54088DS

if(x<=5) return -x+2.5;

应该是x<5


by IKUN54088DS @ 2024-02-15 13:09:16

@wangruiqi36 谢谢,已关


|