c++计算(带符号的)

来源:互联网 发布:苹果数据传输软件 编辑:程序博客网 时间:2024/06/06 01:55
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    int inf=1<<31;
    char s;
    cin>>a>>s>>b;
    switch(s)
    {
    case'+':c=a+b;break;
    case'-':c=a-b;break;
    case'*':c=a*b;break;
    case'/':if(b!=0) c=a/b;else c=inf;
    }
    if (c!=inf) cout<<c; else cout<<"no";
    return 0;

}

此为代码,下方源代码。

感谢你的阅读,谢谢!

2 0
原创粉丝点击