# Untitled

unknown
plain_text
3 years ago
1.5 kB
5
Indexable
Never
```uses crt;//xu ly so lon

//ham tinh tong 2 so lon
function sum(a,b:string):string;
var
tong,nho,x,y,i:longint;
c:string;
begin
nho:=0;
c:='';
while (length(a)<length(b)) do a:='0'+a;
while (length(b)<length(a)) do b:='0'+b; // a va b co do dai bang nhau
for i:=length(a) downto 1 do
begin
x:=ord(a[i]) - ord('0');//so a[i]
y:=ord(b[i]) - ord('0');//so b[i]
tong:= x+y+nho;
nho:=tong div 10;
c:=chr(tong mod 10 +48)+c;
end;
if(nho>0) then c:='1'+c;
sum:=c;
end;

//ham tinh hieu 2 so lon
function sub(a,b:string):string;
var
c:string;
i,hieu,nho:longint;
begin
nho:=0;
c:='';
while(length(a)<length(b)) do a:='0'+a;
while(length(b)<length(a)) do b:='0'+b; // a va b co do dai bang nhau
for i:=length(a) downto 1 do
begin
hieu:=ord(a[i]) - ord(b[i]) -nho;
if (hieu<0) then
begin
hieu:=hieu+10;
nho:=1;
end
else    nho:=0;
c:=chr(hieu+48)+c;
end;
while(length(c)>1) and (c[1]='0') do delete(c,1,1);
sub:=c;
end;

var
f:text;
s1,s2,s3,s4:string;
begin
clrscr;
assign(f,'bai1.inp');reset(f);
close(f);

assign(f,'bai1.out');rewrite(f);
//s3:=sum(s1,s2);
s4:=sub(s1,s2);
write(f,s4);close(f);
//writeln(low(word));
//writeln(high(word));