Program readln 2 big numbers, maximal 100 digits, and add their

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: KMP (Club of young programmers)

Author: Vird
web: www.vird.110mb.com

Program: Scitanie.pas
File exe: Scitanie.exe

Program readln 2 big numbers, maximal 100 digits, and add their.
{ SCITANIE.PAS                                   Copyright (c) Vird }
{ Program ktory nacita 2 velke cisla aj viac ako 100 miestne        }
{ a scita ich.                                                      }
{                                                                   }
{ Author: Vird                                                      }
{ Datum: 20.01.2007                           http://www.trsek.com  }
 
program cisla;
uses crt;
type TVelCislo=record
     cc:string;
     dlzka:integer; {dlzka retazca}
 
     end;
var c,vc:TVelCislo;
    pom:array[1..100]of integer; m,n,i,x,d,d1,d2,d3:integer;
 
 
 
procedure nacit;
  begin
       write('Zadaj 1 cislo = ');
       readln(c.cc);   c.dlzka:=length(c.cc);
       write('Zadaj 2 cislo = ');
       readln(vc.cc);  vc.dlzka:=length(vc.cc);
       write('Vysledok je   = ');
  end;
 
procedure PripocitajVC(cislo:TVelCislo; var vcislo:TVelCislo);
begin
  i:=0;
 
  {...............ZACIATOK USEKU...........}
 
  if cislo.dlzka>=vcislo.dlzka then             {zaciatok ked cislo1>cislo2}
  begin n:=vcislo.dlzka; m:=cislo.dlzka;
          while i<=m do begin
              i:=i+1;
              val(cislo.cc[(m-i)+1],d1,d3);
              if i<=n then val(vcislo.cc[(n-i)+1],d2,d3) else d2:=0;
              d:=d1+d2+x;
              if d>=10 then begin pom[i]:=d mod 10; x:=1; end else
                 begin pom[i]:=d; x:=0; end;
          end;
     if x>0 then pom[m+1]:=x;
 
 
    if pom[m+1]>0 then write(pom[m+1]); end; for i:=m downto 1 do write(pom[i]);
 
 
 
 
 
if cislo.dlzka<vcislo.dlzka then             {zaciatok ked cislo1<cislo2}
  begin m:=vcislo.dlzka; n:=cislo.dlzka;
          while i<=m do begin
              i:=i+1;
              val(vcislo.cc[(m-i)+1],d1,d3);
              if i<=n then val(cislo.cc[(n-i)+1],d2,d3) else d2:=0;
              d:=d1+d2+x;
              if d>=10 then begin pom[i]:=d mod 10; x:=1; end else
                 begin pom[i]:=d; x:=0; end;
          end;
     if x>0 then pom[m+1]:=x;
 
     if pom[m+1]>0 then write(pom[i]); for i:=m downto 1 do write(pom[i]);
 
 
         {.....KONIEC USEKU........}
 
 
 
 
 
    end;
end;
 
 
begin
 writeln('Program na scitanie 2 n-miestnych cisel');
 nacit;
 pripocitajvc(c,vc);
 readln;
end.