Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Autor:Paul4games
- program Project1;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- function Adunare(nr,nr1: integer): string; stdcall;
- var
- Str,Str1: string;
- j,i,k: integer;
- a,b: array of char;
- begin
- Str := IntToStr(nr);
- Str1 := IntToStr(nr1);
- if Length(Str)>Length(Str1) then
- repeat
- Insert('0', Str1, 1);
- until Length(Str1)=Length(Str)
- else if Length(Str1)>Length(Str) then
- repeat
- Insert('0', Str1, 1);
- until Length(Str)=Length(Str1);
- SetLength(a, Length(Str)+1);
- SetLength(b, Length(Str1)+1);
- for j := Length(Str) downto 1 do
- begin
- a[j] := Str[j];
- b[j] := Str1[j];
- end;
- a[0] := '0';
- b[0] := '0';
- k := 0;
- for i := Length(Str) downto 0 do
- begin
- if StrToInt(a[i])+StrToInt(b[i])<>0 then
- begin
- if k>0 then
- begin
- if StrToInt(a[i]) + StrToInt(b[i]) + k>9 then
- begin
- k := StrToInt(a[i]) + StrToInt(b[i]) + k;
- Result := IntToStr(k mod 10) + Result;
- k := k div 10;
- end
- else
- begin
- if (StrToInt(a[i+1]) + StrToInt(b[i+1])) or (StrToInt(a[i+1]) + StrToInt(b[i+1]) + k)>9 then
- begin
- Result :=IntToStr(StrToInt(a[i]) + StrToInt(b[i])+ k) + Result;
- k := k div 10;
- end
- else
- begin
- Result := IntToStr(StrToInt(a[i]) + StrToInt(b[i]));
- end;
- end;
- end
- else
- begin
- if StrToInt(a[i]) + StrToInt(b[i])>9 then
- begin
- k := StrToInt(a[i]) + StrToInt(b[i]);
- Result := IntToStr(k mod 10) + Result;
- k := k div 10;
- end
- else
- Result := IntToStr(StrToInt(a[i])+StrToInt(b[i])) + Result;
- end;
- end
- else
- if (StrToInt(a[i+1]) + StrToInt(b[i+1])) or (StrToInt(a[i+1]) + StrToInt(b[i+1]) + k)>9 then
- Result := IntToStr(k) + Result;
- end;
- end;
- var
- t: string;
- begin
- t := Adunare(3888, 333);
- WriteLn(t);
- ReadLn;
- end.
Advertisement
Add Comment
Please, Sign In to add comment