文章

4

粉丝

0

获赞

42

访问

1.7k

头像
计算表达式 题解:

纯C语言

#include <stdio.h>
#include <ctype.h> 
//运算符优先级 
int priority(char ch){
    if(ch=='+'||ch=='-') return 1;
    if(ch=='*'||ch=='/') return 2;
    return 0;
}
//计算
int calculate(int a,int b,char ch){
    switch(ch){
        case '+':return a+b;
        case '-':return a-b;
        case '*':return a*b;
        case '/':return a/b;
        default:return 0;
    }

 int main(){
    char s[100];
    scanf("%s",s);
    getchar(); 
    char op[100];
    int op_top=-1;//运算符栈 
    int num[100];
    int num_top=-1;//操作...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发