16分蒟蒻,求求大佬

B2047 分段函数

yi18600361898 @ 2024-03-02 22:00:45

#include <bits/stdc++.h>
using namespace std;
int main(){
    double x;
    double y;
    if(x>=0 and x<5){
        y=-1*x+2.5;
    }
    else if(x>5 and x<10){
        y=-2-1.5*(x-3)*(x-3);
    }
    else if(x>=10 and x<20){
        y=x/2-1.5;
    }
    cout<<fixed<<setprecision(3)<<y;
    return 0;
}

by cute_overmind @ 2024-03-02 22:04:08

没输入你在干嘛


by penguin_is_cool @ 2024-03-02 22:42:57

@yi18600361898 你输入呢?


by yi18600361898 @ 2024-03-03 11:21:26

我太聪明了 @penguin_is_cool


by yi18600361898 @ 2024-03-03 11:24:01

@penguin_is_cool

还有两个点红


by penguin_is_cool @ 2024-03-03 17:31:29

@yi18600361898 else if (x>=5 and x<10)第二个判断条件换一下


by penguin_is_cool @ 2024-03-03 17:33:04

@yi18600361898 第二个,y=2-1.5(x-3)(x-3)


by yi18600361898 @ 2024-03-04 19:42:50

@penguin_is_cool

过了 谢谢dalao 已关注


by shuiyou1 @ 2024-08-27 15:00:26

@penguin_is_cool 为什么我用(0<=a<5)这个就得不行,用(0<=a&&a<5)能得满分,这俩个有什么区别??请赐教


by langyichen @ 2024-09-15 12:00:00

@shuiyou1 0<=a<5是先判断0<=a,然后用一个布尔值和5比较。所有判断3个数间关系的都要用&&连接


|