Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   Калькулятор Pascal (https://forum.antichat.xyz/showthread.php?t=189707)

dark-klin 23.03.2010 21:47

Калькулятор Pascal
 
Цитата:

program crt;
var
a,b,c,v,x,s: real;
Begin
Write('Введи первое значение: ');
ReadLn(a);
Write('Введи второе значение: ');
ReadLn(b);
c:=a+b;
x:=a-b;
v:=a*b;
s:=a/b;
WriteLn('Сложение ',a,'+',b,'=',c);
WriteLn('Вычитание ',a,'-',b,'=',x);
WriteLn('Умножение ',a,'*',b,'=',v);
WriteLn('Деление ',a,'/',b,'=',s);
End.
Помогите сделать из этого нормальный калькулятор. С возведением в квадрат, куб...

Fox_NICK 23.03.2010 22:02

ЛИбо так
x - Ваше число (integer, real)
N - степень (integer)
S - здесь будет результат (integer, real)
i - счётчик (integer)

S:=1;
for i:=1 to N do S:=S*x;

Либо так допавишь у себя в коде

Var chisl, stepen:Real;
Function stn(Var chislo, stepen:Real) of Real;
Var per:real;
Begin
Per:= Abs(chislo);
If chislo < 0 Then Pow:= (-1)*Exp((stepen)*Ln(per))
Else Pow:= Exp((stepen)*Ln(per));
end;
Begin
clrscr;
Write('Введите число = '); readln(chisl);
Write('Введите степень = '); readln(stepen);
Writeln('Возведя в степень получаем = ',stn);
readln;
readln;

Helium 24.03.2010 11:06

Извлечение ЦЕЛОГО квадратного корня
X:longint {это переменная из которой извлекать}
I:longint {счетчик,флаг корня}
b:longint {корень}
for i:=1 to x/2 do
if i*i=x then b:=i
if b=0 then writeln ('корней нет');
if b>0 then writeln ('корень-',b);

leva0691 24.03.2010 12:27

а чем собственно проблема? задай переменную, которая при нажатии на копку будит умножаться на себя саму - вот тебе квадрат, точно так же куб.....или я что-то не понял?

Helium 24.03.2010 12:44

И,да вот готовый
PHP код:

uses wincrt;
label 1,2,3,4;
type zz=array[1..20of string;
     
aa=array[1..20of byte;
     
kk=array[1..30of real;
var
i,n,m,k,j,o,l,xinteger;   a,b,v:string;
c:array[1..10of string;
f:text;     result:real;

function 
calculate(x:string):string;
var 
i,j,k:integer;  a:zzt:aa;  s,s1,s2:realh:string;
c1:integerp:integerc:kk;
begin
k
:=1;
s:=0;
s1:=1;
for 
i:=1 to 20 do
a[i]:='';
for 
i:=1 to 30 do
t[i]:=0;
 for 
i:=1 to length(x) do
 
begin
 
if (x[i]='+') or (x[i]='-') or (x[i]='*') or (x[i]='/')
  
then
  begin
   
if x[i]='+' then t[k]:=1;
   if 
x[i]='-' then t[k]:=2;   {разделяет плюсыминусы и цифры}
   if 
x[i]='*' then t[k]:=3;
   if 
x[i]='/' then t[k]:=4;
   
k:=k+1;
   
end
  
else
  
a[k]:=a[k]+x[i];
   
end;
   for 
i:=1 to k do             {переводит в числовой массив}
   
val(a[i],c[i],c1);
   if 
x[1]='-' then p:=1;
   if (
p<>1) and (t[1]=2) and (t[2]<>3) and (t[2]<>4then s:=c[1];
   if (
t[1]=2) and (t[2]=2then s:=c[1];
if (
t[1]=1) or (k=1then s:=c[1];        {начальные значения}

for 
i:=1 to k do
   
begin
    
if (t[i]=3then
    begin
    
if (t[i-1]<>2) and (t[i-1]<>3) and (t[i-1]<>4then
    begin
    
{s:=s+c[i]*c[i+1];}
    
s1:=c[i]*c[i+1];
    {
s:=s+s1;}
    
end;                           {знак *}
    if (
t[i-1]=2then
    begin
   
{s:=s-c[i]*c[i+1];}
    
s1:=-c[i]*c[i+1];
    {
s:=s+s1;}
    
end;
    if (
t[i-1]=4) or (t[i-1]=3then
    begin
    s1
:=s1*c[i+1];
     {
s:=s+s1;}
     
end;
    
end;


    if (
t[i]=4then
    begin
    
if (t[i-1]<>2) and (t[i-1]<>3) and (t[i-1]<>4then
    begin
    
{s:=s+c[i]/c[i+1]; }
    
s1:=c[i]/c[i+1];
    
end;
    if 
t[i-1]=2 then
    begin                             
{знак /}
    
s1:=-c[i]/c[i+1];
    
end;
    if (
t[i-1]=3) or (t[i-1]=4then
    begin
    s1
:=s1/c[i+1];
    {
s:=s1+s; }
    
end;
    
end;
    if (
t[i+1]<>3) and (t[i+1]<>4) and (s1<>1then
    begin
    s
:=s+s1;
    
s1:=1;
    
end;
   
end;
for 
i:=1 to k do
begin
if t[i]=2
then
begin
if (i=1) and (p=1) and (t[2]=2then s:=s-c[2];
if (
t[i+1]<>4) and (t[i+1]<>3then
s
:=s-c[i+1]                             {знак -}
else
s:=s+c[i];
end;

if (
t[i]=1) and (t[i+1]<>3) and (t[i+1]<>4)
then
s
:=s+c[i+1];                            {знак +}
{
writeln(c[i]:5:3);}
end;

str(s:5:3,h);
calculate:=h;
end;


begin
assign
(f,'calc.in');
reset(f);
readln(f,a);
1:
k:=0;
for 
i:=1 to length(a) do
if 
a[i]='(' then k:=k+1;
if 
k=0 then goto 2;
i:=0;
l:=0;
while 
i<=length(a) do
begin
3
: if l>k then goto 2;
i:=i+1;
if 
a[i]='(' then
begin
l
:=l+1;
n:=i;
b:='';
while 
a[i]<>')' do
begin
if (a[i]='(') and (a[i+1]='('then goto 3;
if 
a[i]='(' then
begin
n
:=i;
i:=i+1;
b:='';
end;
b:=b+a[i];
{
writeln(b);}
i:=i+1;
end;
m:=i;
a:=copy(a,1,n-1)+calculate(b)+copy(a,m+1,length(a));
{
writeln(a);}
goto 
1;
end;
end;
2:
val(calculate(a),result,o);
write(result:5:3);
end



Время: 07:49