Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.18 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils, Math;
  7.  
  8. Function InCase(str: String;  toch:Integer) : Double;
  9. var i, chislo: Integer;
  10. var number: Double;
  11. begin
  12.   number:=0;
  13.   for i:=1 to toch do
  14.     begin
  15.       case str[i] of
  16.         '1': chislo:=1;
  17.         '2': chislo:=2;
  18.         '3': chislo:=3;
  19.         '4': chislo:=4;
  20.         '5': chislo:=5;
  21.         '6': chislo:=6;
  22.         '7': chislo:=7;
  23.         '8': chislo:=8;
  24.         '9': chislo:=9;
  25.         '0': chislo:=0;
  26.       else begin
  27.         writeln('Ne verno zadano chislo');
  28.         readln;
  29.         exit; //or result
  30.         end;
  31.       end;
  32.     number:=number + chislo*Power(10, (toch-i));
  33.     end;
  34.    Result := number;
  35. end;
  36.  
  37. var
  38. a,b: String;
  39. i,tochka, tochka2, chislo, n, n2, test: Integer;
  40. a_f, a_f2, b_f, b_f2: Double;
  41. begin
  42.   writeln('Vvedite pervoje chislo');
  43.   readln(a);
  44.   writeln('Vvedite vtoroje chislo');
  45.   readln(b);
  46.   writeln('Vy vveli chisla: ', a, ' i ', b);
  47.   tochka:=0;
  48.   n:=length(a);           //dlina pervoj stroki
  49.   for i:=1 to n do
  50.       if(a[i] = '.') or (a[i] = ',') then
  51.         begin                                  //nahodim gde nahoditsia tochka v pervom chisle
  52.           tochka:=i-1;
  53.           break;
  54.         end;
  55.   tochka2:=0;
  56.   n2:=length(b);          //dlina vtoroj stroki
  57.   for i:=1 to n do
  58.       if(b[i] = '.') or (b[i] = ',') then       //nahodim gde nahoditsia tochka vo vtorom chisle
  59.         begin
  60.           tochka2:=i-1;
  61.           break;
  62.         end;
  63.     if(tochka<>0) then
  64.       a_f:=InCase(a, tochka)
  65.     else a_f:=InCase(a, n);
  66.     if(tochka2<>0) then
  67.       b_f:=InCase(b, tochka2)
  68.     else b_f:=InCase(b, n2);
  69.  
  70.       if(tochka<>0) then
  71.         begin
  72.           Delete(a, 1, tochka+1);
  73.           n:=n-tochka-1;
  74.           a_f2:=InCase(a, n);
  75.         end;
  76.  
  77.       if(tochka2<>0) then
  78.         begin
  79.           Delete(b, 1, tochka2+1);
  80.           n2:=n2-tochka2-1;
  81.           b_f2:=InCase(b, n2);
  82.         end;
  83.     test:=1;
  84.     for i:=1 to n do
  85.        test:=test*10;
  86.     a_f:=a_f+a_f2/test;
  87.     test:=1;
  88.     for i:=1 to n2 do
  89.        test:=test*10;
  90.     b_f:=b_f+b_f2/test;
  91.      a_f:=a_f+b_f;
  92.      Writeln('Summa chisel = ', a_f:0:5);
  93.   readln;
  94. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement