求1个pascal 计算器程序

快!!!!!!!!!!!!!!!!!!!!!!!!!!!!科学计算器 有括号
2026年09月27日 02:36
有5个网友回答
网友(1):

var s,ch:string;
top1,top2,i,t,j,f,k:longint;
a1:array[0..250] of longint;
a2:array[0..250] of char;
b:array[0..250] of longint;
begin
readln(s);
s:=s+'#';
i:=1;
top1:=1;
a1[top1]:=-1;a2[top1]:='#';
while top1>0 do
begin
t:=i;
while s[i] in['0'..'9'] do i:=i+1;
if i>t then
begin
ch:='';
for j:=t to i-1 do
ch:=ch+s[j];
top2:=top2+1;
val(ch,b[top2]);
end;
case s[i] of
'+':f:=1;
'-':f:=1;
'*':f:=2;
'^':f:=3;
'(':f:=0;
')':f:=0;
'#':f:=-1;
end;
while (f<=a1[top1]) and (s[i]<>'(') do
begin
if a2[top1]<>'(' then top2:=top2-1;
case a2[top1] of
'+':b[top2]:=b[top2]+b[top2+1];
'-':b[top2]:=b[top2]-b[top2+1];
'*':b[top2]:=b[top2]*b[top2+1];
'^':begin k:=1;for j:=1 to b[top2+1] do k:=k*b[top2];b[top2]:=k; end;
'#':if f=-1 then begin top1:=0;break; end;
end;
top1:=top1-1;
end;
if (top1>0) and (f>a1[top1]) and (s[i]<>')') or (s[i]='(') then
begin
top1:=top1+1;
a1[top1]:=f;
a2[top1]:=s[i];
end;
i:=i+1;
end;
writeln(b[1]);
end.

网友(2):

是哪种计算器?
复杂到什么程度?
还是简单加减乘除计算?

网友(3):

program JiSuanQi;
var
a.b:integer,
plus.minus.multiply.divide:real,

begin
readln(a.b),
plus:=a+b,
minus:=a-b,
multiply:=a*b,
divide:=a/b,
readln(x),
if x=1 then writeln(’a+b=’.a.’+’.b.’=’.plus),
if x=2 then writeln(’a-b=’.a.’-’.b.’=’.minus),
if x=3 then writeln(’a*b=’.a.’*’.b.’=’.multiply),
if x=4 then writeln(’a/b=’.a.’/’.b.’=’.divide),
readln,
end.

网友(4):

var
temp:longint;
ans,a,b:real;
ch:char;
st,sta,stb:string;
begin
ans:=0;
writeln('Type EXIT to return...');
readln(st);
repeat
ch:=' ';
if pos('-',st)<>0 then ch:='-';
if pos('+',st)<>0 then ch:='+';
if pos('*',st)<>0 then ch:='*';
if pos('/',st)<>0 then ch:='/';
if ch=' ' then
begin
writeln('error');
readln(st);
continue;
end;
stb:=copy(st,pos(ch,st)+1,length(st));
val(stb,b,temp);
if (temp<>0) or (ch='/') and (b=0) then
begin
writeln('error');
readln(st);
continue;
end;
if pos(ch,st)<>1 then
begin
sta:=copy(st,1,pos(ch,st)-1);
val(sta,a,temp);
if temp<>0 then
begin
writeln('error');
readln(st);
continue;
end;
ans:=a;
end;
case ch of
'+':ans:=ans+b;
'-':ans:=ans-b;
'*':ans:=ans*b;
'/':ans:=ans/b;
end;
writeln(ans:0:10);
readln(st);
until st='EXIT';
end.

科学计算器?不会还要算三角函数吧?这难度也太高了点。

网友(5):

是哪种计算器?
复杂到什么程度?
还是简单加减乘除计算?要括号?好难