求助大佬

B2047 分段函数

junbeder @ 2024-08-02 18:13:17


by junbeder @ 2024-08-02 18:14:42

我的代码:```

include<bits/stdc++h>

using namespace std; signed main(){ double x,y; cin>>x; if(0<=x<=5) y=-x+2.5; else if(5<=x<10) else if(10<=x<20) y=x/2-1.5; printf("%.3lf",y) return 0; }


by junbeder @ 2024-08-02 18:15:23

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

by hyl_____ @ 2024-08-02 18:15:25

? 代码呢


by haimingbei @ 2024-08-02 18:27:40

@junbeder 要用&&(逻辑运算)


by haimingbei @ 2024-08-02 18:28:50

@junbeder &&表示并且 AC,求关

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n, m;
    cin >> n;
    if(n >= 0 && n < 5)
    {
        cout << fixed << setprecision(3) << 2.5 - n;
        return 0;
    }
    if(n >= 5 && n < 10)
    {
        cout << fixed << setprecision(3) << 2.0 - (n-3.0)*(n - 3.0) * 1.5;
        return 0;
    }
    cout << fixed << setprecision(3) << n / 2.0 - 1.5;
}

by junbeder @ 2024-08-02 18:31:01

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

by junbeder @ 2024-08-02 18:31:49

@haimingbei谢谢,已关。


by youthiscoming @ 2024-08-24 07:42:12

@haimingbei

又在刷水题


by haimingbei @ 2024-08-24 09:26:35

@youthiscoming 你这么早就在线了?(7点???)


by youthiscoming @ 2024-08-24 18:03:37

@haimingbei

趁早刷题,早点红名


| 下一页