第三章例3-9

时间:2022-12-03 21:25:12
/* 求解简单的四则运算表达式 */
#include<stdio.h>
int main(void)
{
    double value1,value2;
    char op;

    printf("Type in an expression:");
    scanf_s("%lf%clf",&value1,&op,&value2);
    switch(op){
    case'+':
        printf("=%.2f\n",value1+value2);
        break;
    case'-':
        printf("=%.2f\n",value1-value2);
        break;
    case'*':
        printf("=%.2f\n",value1*value2);
        break;
    case'/':
        printf("=%.2f\n",value1/value2);
        break;
    default:
        printf("Unknown operator\n");
        break;

    }


    return 0;
}

第三章例3-9