

hi, chào các bạn, mình mới nghĩ ra được một cách làm tính với các số nguyên quá lớn, số đươc nhập vào dưới dạng string, kết quả cũng là kiểu string luôn. Chỗ nào thiếu sót gì ae chỉnh lại hộ mình nha
Code đây:
@trà nguyễn hữu nghĩa @ka1412 @son_gohan @Nguyễn Khoa
Code đây:
Mã:
Program cong_tru_nhan_chia;
uses crt;
var n,i:LongInt;
z,s:ansistring;
//cong
function cong(s2,s1:ansistring):ansistring;
var z:ansistring;
n1,n2,i,g,d,du:LongInt;
code:Integer;
begin z:='';
while Length(s2)>Length(s1) do s1:='0'+s1;
while Length(s1)>Length(s2) do s2:='0'+s2;
s1:='0'+s1;s2:='0'+s2;g:=Length(s2);du:=0;
for i:=g downto 1 do
begin
Val(s1[i],n1,code);
Val(s2[i],n2,code);
d:=n1+n2+du;
if d>=10 then du:=1 else du:=0;
d:=d MOD 10;
z:=Chr(d+48)+z;
end;
if z[1]='0' then delete(z,1,1);
cong:=z;
end;
//tru
function tru(sl,sb:ansistring):ansistring;
var n1,n2,i,g,d,du:LongInt;
z:ansistring;
code:Integer;
begin z:='';
if length(sl)<length(sb) then exit('0');
if (length(sl)=length(sb)) then
for i:=1 to length(sl) do if (ord(sl[i])<ord(sb[i])) then exit('0');
while length(sb)<Length(sl) do sb:='0'+sb;
g:=Length(sl);du:=0;
for i:=g downto 1 do
begin
Val(sl[i],n1,code);
Val(sb[i],n2,code);
if n1<n2+du then
begin d:=n1+10-n2-du;du:=1; end
else begin d:=n1-n2-du;du:=0; end;
z:=Chr(d+48)+z;
end;
if z[1]='0'then delete(z,1,1);
tru:=z;
end;
//nhan
function nhan(s1,s2:ansistring):ansistring;
var n,i,g,f,e,nho,h:LongInt;
z,s,r:ansistring;
begin g:=length(s1);z:='0';
while g>=1 do
begin s:='';nho:=0;
val(s1[g],e);
for i:=length(s2) downto 1 do
begin
val(s2[i],f);
h:=f*e+nho;
s:=chr((h mod 10)+48)+s;
nho:=h div 10;
end;
str(nho,r);
if nho>0 then s:=r+s;
for i:=g to length(s1)-1 do s:=s+'0';
z:=cong(z,s); dec(g);
end;
exit(z);
end;
//chia lay phan nguyen
function chia(sbc,sc:ansistring):ansistring;
var i,n,j:longint;
z,r:ansistring;
begin r:='';z:='1';r:=sc;
for i:=1 to length(sbc)-length(sc)-1 do z:=z+'0';
if z='1' then z:='0' else sc:=nhan(sc,z);
//for i:=1 to length(sbc) do r:=r+'0';
while tru(sbc,sc)<>'0' do
begin
sc:=cong(sc,r);
z:=cong(z,'1'); writeln(sc);
end;
chia:=z;
end;
BEGIN
END.