68求助

B2047 分段函数

Tairitsu_Cat @ 2023-08-17 20:14:40

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

by Anli_li_father @ 2023-08-17 20:16:32

if(5<=x&&x<10) 2-1.5*(x- 3)*(x - 3);

这句话是不是少了点什么


by __xux__ @ 2023-08-17 20:17:48

@Tairitsu_Cat 咋还少个y=

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

求关注~


|