计算器

发布于 2019-12-17  0 次阅读


    #include
    #include
    #include
    void main()
    {
        float a,b,f;
        char c;char e[100];
        if(scanf("%f%c%f",&a,&c,&b))
        {
            switch(c)
            {
                case '+':printf("=%f\n",a+b);break;
                case '*':printf("=%f\n",a*b);break;
                case '-':printf("=%f\n",a-b);break; 
                case '/':printf("=%f\n",a/b);break;
                case '%':printf("=%d\n",(int)a%(int)b);break;
            }
        }    
        else 
        {
            scanf("%s%f",&e,&f);
            if(strcmp(e,"sin")==0) printf("%f\n",sin(f));
            else if(strcmp(e,"cos")==0) printf("%f\n",sin(f));
            else if(strcmp(e,"sqrt")==0) printf("%f\n",sqrt(f));
            else if(strcmp(e,"square")==0) printf("%f\n",f*f);
            else if(strcmp(e,"int")==0) printf("%d\n",(int)f);
            else printf("无法求解");
        } 
    }

本当の声を響かせてよ