早教吧作业答案频道 -->其他-->
求用以下类似程序编一个可以计算括号的计算器#include#definesmax10#defineemax255intpower(intx,inty){intt,s=1;for(t=0;t=48&&ex[i]=rinput&&rtop!=0){//计算//数字出战top=top-1;x=s[top];top=top-1;y=s[top];s[top]=calc
题目详情
求用以下类似程序编一个可以计算括号的计算器
#include
#define smax 10
#define emax 255
int power(int x,int y)
{
int t,s=1;
for (t=0; t=48 && ex[i]=rinput && rtop!=0)
{
//计算
//数字出战
top=top-1;
x=s[top];
top=top-1;
y=s[top];
s[top]=calc(o,x,y);
top=top+1;
//读出下一个栈顶符号
otop=otop-1;
o=op[otop];
if (o=='+')
rtop=0;
else
if (o=='-') rtop=1;
}
//原先的放回
op[otop]=o;
otop=otop+1;
//新的符号入栈
op[otop]=ex[i];
otop=otop+1;
}
}
i=i+1;
}
while (otop!=0)
{
//数字出战
top=top-1;
x=s[top];
top=top-1;
y=s[top];
//符号出栈
otop=otop-1;
o=op[otop];
s[top]=calc(o,x,y);
top=top+1;
}
ans= s[0];
//输出结果
printf("%s=%d\n",ex,ans);
}
#include
#define smax 10
#define emax 255
int power(int x,int y)
{
int t,s=1;
for (t=0; t=48 && ex[i]=rinput && rtop!=0)
{
//计算
//数字出战
top=top-1;
x=s[top];
top=top-1;
y=s[top];
s[top]=calc(o,x,y);
top=top+1;
//读出下一个栈顶符号
otop=otop-1;
o=op[otop];
if (o=='+')
rtop=0;
else
if (o=='-') rtop=1;
}
//原先的放回
op[otop]=o;
otop=otop+1;
//新的符号入栈
op[otop]=ex[i];
otop=otop+1;
}
}
i=i+1;
}
while (otop!=0)
{
//数字出战
top=top-1;
x=s[top];
top=top-1;
y=s[top];
//符号出栈
otop=otop-1;
o=op[otop];
s[top]=calc(o,x,y);
top=top+1;
}
ans= s[0];
//输出结果
printf("%s=%d\n",ex,ans);
}
▼优质解答
答案和解析
将()当成op处理即可
看了 求用以下类似程序编一个可以计...的网友还看了以下:
电场表达式:E=K(i∙y+j∙x),i,j是单位向量,求电荷分布.(静态电场)只要把思路说清楚就 2020-05-13 …
英语翻译E.Z.I/O=(简单输入/输出)E.Z.I/O是一直活跃在电音舞曲圈内的liveprod 2020-06-07 …
d,c,e,e,i,t,x组成单词 2020-06-09 …
main(){unionEXAMPLE{struct{intx,y;}in;inta,b;}e;e 2020-06-12 …
用以下英文宇母填在上a,a,a,a,a,a,b,e,e,d,e,e,e,e,e,e,f,g,g用以 2020-06-24 …
求下面函数的解释,看不懂function A = fun(W)[m,n] = size(W); e 2020-06-27 …
设E表示由n阶单位矩阵第i行与第j行互换得到的初等矩阵,则,E(I,J)^2=.设E表示由n阶单位 2020-07-16 …
3、将C,C,E,E,I,N,S等7个字母随机的排成一行,那末恰好排成英文单词SCIENCE的概率 2020-07-30 …
2-1设文法G[E]的产生式集为:EàE+T|E-T|TTàT*F|T/F|FFà(E)|i(1)给 2020-11-26 …
英语向高人求教!写几句话.每句开头的第一个字母分别是“L,i,U,F,E,i,F,E,i,w,o,a 2020-12-15 …