关于C语言的简单问题 是作业 急急急!+30分

[复制链接]
查看11 | 回复2 | 2008-3-25 21:56:45 | 显示全部楼层 |阅读模式
#includevoid main() {double a,b; char op; scanf("%lf%c%lf",&a,&op,&b); if(op=='+')printf("%f+%f=%f",a,b,a+b); if(op=='-')printf("%f-%f=%f",a,b,a-b); if(op=='*')printf("%f*%f=%f",a,b,a*b); if(op=='/')printf("%f/%f=%f",a,b,a/b);} #includevoid main() {double a,b; char op; scanf("%lf%c%lf",&a,&op,&b); switch(op) { case '+':printf("%f+%f=%f",a,b,a+b);break; case '-':printf("%f-%f=%f",a,b,a-b);break; case '*':printf("%f*%f=%f",a,b,a*b);break; case '/':printf("%f/%f=%f",a,b,a/b);break; default:printf("\n输入有误!");break; } }
回复

使用道具 举报

千问 | 2008-3-25 21:56:45 | 显示全部楼层
#includevoid main(){char c;float t,s;printf("Input:\n");scanf("%f",&s);while((c=getchar())!='\n'){scanf("%f",&t);switch(c){case '+':s+=t;break;case '-':s-=t;break;case '*':s*=t;break;case '/':s/=t;break;default:printf("Error!");}printf("%f\n",s);}}
回复

使用道具 举报

千问 | 2008-3-25 21:56:45 | 显示全部楼层
个人感觉建个二叉树,根据表达式建树,然后后序或先序遍历求值,你说的ifelse怎么做不清楚,不考虑括号什么的吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行