模拟简单计算器编程c语言,模拟计算器程序

满意答案

00e27ab806e4881f8254fe7ae8741834.png

zjwandy2010

2014.09.16

00e27ab806e4881f8254fe7ae8741834.png

采纳率:41%    等级:12

已帮助:5892人

var c:char; sym:array[0..30]of char; num:array[0..30]of longint; ts,tn:shortint; x:longword; procedure calcu; var p:char; x,x2:longint; x1:real; begin p:=sym[ts];dec(ts); x2:=num[tn];dec(tn); x1:=num[tn];dec(tn); case p of '+':x:=trunc(x1)+x2; '-':x:=trunc(x1)-x2; '*':x:=trunc(x1)*x2; '/':x:=trunc(x1) div x2; '^':x:=trunc(exp(x2*ln(x1))); end; if tn<0 then inc(tn); //判负 inc(tn);num[tn]:=trunc(x); end; procedure push; begin inc(ts);sym[ts]:=c; read(c); end; begin fillchar(num,sizeof(num),0); ts:=0;tn:=0; read(c); while not eoln do case c of '0'..'9':begin x:=0; repeat x:=x*10+ord(c)-ord('0'); read(c); until not(c in['0'..'9']); inc(tn);num[tn]:=x; end; '+','-':begin while(ts>0)and(sym[ts]<>'(')do calcu; push; end; '*','/':begin while(ts>0)and(sym[ts]in['*','/','^'])do calcu; push; end; '^':begin while(ts>0)and(sym[ts]='^')do calcu; push; end; '(':push; ')':begin while(sym[ts]<>'(')do calcu; dec(ts);read(c); end; end; if c in['0'..'9']then begin inc(tn);num[tn]:=ord(c)-ord('0'); end else if c=')' then begin while(sym[ts]<>'(')do calcu; dec(ts);read(c); end; while sym[ts]='(' do dec(ts); while ts>0 do calcu; writeln(num[1]); end. //pascal语言的

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值