输入两个整数和一个四则运算符,根据运算符计算并输出其运算结果(和、差、积、商、余之一)。注意做整除及求余运算时,除数不能为零

输入两个整数和一个四则运算符,根据运算符计算并输出其运算结果(和、差、积、商、余之一)。注意做整除及求余运算时,除数不能为零

你好,代码如下:

#include<stdio.h>
int main()
{
    int a,b;
    char ch;
    scanf("%d %d %c",&a,&b,&ch);
    switch(ch)
    {
        case '+':
            printf("%d",a+b);break;
        case '-':
            printf("%d",a-b);break;
        case '*':
            printf("%d",a*b);break;
        case '/':
            if(b!=0)
                printf("%d",a/b);break;
        case '%':
            if(b!=0)
                printf("%d",a%b);break;      
    }
    return 0;
}

如果对题主有帮助,望采纳!