C语言编译四则运算

时间:2021-10-26 20:40:50
    float a = 0, b = 0, c = 0;
    char count = 0;
    printf("输入运算\n");
    scanf("%f%c%f",&a,&count,&b);
        switch (count) {
        case'+':{
            c = a + b;
        }
            printf("结果为%.2f",c);
            break;
        case'-':{
            c = a - b;
        }
            printf("结果为%.2f",c);
        case'*':{
                c = a * b;
            }
            printf("结果为%.2f",c);
            break;

        case'/':{
            if (b == 0) {
                printf("节操呢");
                break;
            }
                 c = a / b;
            }
            printf("结果为%.2f",c);
            break;
          
            
        default:
            break;
    }