#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int result(int a,char b,int c)
{
    int i;
    switch (b)
    {
    case '+':
        i=(a+c);
        break;
    case '-':
        i=(a-c);
        break;
    case '*':
        i=(a*c);
        break;
    case '/':
        i=(a/c);
        break;

    default:
        i=0;
        break;
    }
    return i;
}


int main(int argc, char *argv[])
{
    int  a=0,b=0;
    char c,cs;
    char *s,*p;
    bool t=1;
    s=(char*)malloc(100);
    p=s;
    while (c=getchar())
    {

        if (isdigit(c))
        {
            *s=c;
            s++;
        }
        else
        {

            if (t)
            {
                cs=c;
                *s='\0';
                s=p;
                a=atoi(s);
                t=0;
            }
            else
            {
                *s='\0';
                s=p;
                b=atoi(s);
                a=result(a,cs,b);
            }

        }
        if (c=='=')
        {
            printf("结果:%d",a);
            free(s);
            break;
        } ;

    }


    return 0;
}

相关文章:

  • 2022-01-14
  • 2021-09-03
  • 2021-08-05
  • 2021-07-07
  • 2021-07-07
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案