Калькулятор Pascal

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by dark-klin, 23 Mar 2010.

  1. dark-klin

    dark-klin Member

    Joined:
    10 Aug 2009
    Messages:
    98
    Likes Received:
    7
    Reputations:
    0
    Помогите сделать из этого нормальный калькулятор. С возведением в квадрат, куб...
     
  2. Fox_NICK

    Fox_NICK Elder - Старейшина

    Joined:
    10 Jan 2007
    Messages:
    45
    Likes Received:
    5
    Reputations:
    0
    ЛИбо так
    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;
     
  3. Helium

    Helium New Member

    Joined:
    6 Jan 2010
    Messages:
    22
    Likes Received:
    3
    Reputations:
    0
    Извлечение ЦЕЛОГО квадратного корня
    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);
     
  4. leva0691

    leva0691 New Member

    Joined:
    30 Sep 2009
    Messages:
    0
    Likes Received:
    0
    Reputations:
    0
    а чем собственно проблема? задай переменную, которая при нажатии на копку будит умножаться на себя саму - вот тебе квадрат, точно так же куб.....или я что-то не понял?
     
  5. Helium

    Helium New Member

    Joined:
    6 Jan 2010
    Messages:
    22
    Likes Received:
    3
    Reputations:
    0
    И,да вот готовый
    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.