2 条题解

  • 2

    #include <iostream>
    using namespace std;
    int main( )
    {
    int a,b;char c;
    cin>>a>>b;
    cin>>c;
    switch(c)
    {
    case '+':cout<<a+b;break;
    case '-':cout<<a-b;break;
    case '*':cout<<a*b;break;
    case '/':if(b==0)cout<<"Divided by zero!";else cout<<a/b;break;
    default:cout<<"Invalid operator!";
    }
    }

  • 1
    #include <iostream>
    #include <cstdio>
    using namespace std;
    int main() {
        int a, b;
        char op;
        cin >> a >> b >> op;
        switch (op) {
            case '+':
                cout << a + b;
                break;
            case '-':
                cout << a - b;
                break;
            case '*':
                cout << a * b;
                break;
            case '/':
                if (b == 0) {
                    cout << "Divided by zero!";
                } else {
                    cout << a / b;
                }
                break;
            default:
                cout << "Invalid operator!";
        }
        return 0;
    }
    
    
  • 1

信息

ID
2348
难度
3
分类
(无)
标签
递交数
142
已通过
71
通过率
50%
被复制
2
上传者