VCT Trừ 2 số cực lớn
VD:
981283746656541249010234 – 1991119911 = 981283746656539257890323
0 bình luận về “VCT Trừ 2 số cực lớn VD: 981283746656541249010234 – 1991119911 = 981283746656539257890323”
uses crt; var s1,s2:string; function tru(x1,x2:string):string; var tam:string[2]; du,i,so1,so2:byte; begin while length(x1)<>length(x2) do if length(x1)<length(x2) then insert(‘0’,x1,1) else insert(‘0’,x2,1); du:=0; tru:=”; for i:=length(x1) downto 1 do begin val(x1[i],so1); val(x2[i],so2); if so1<(so2+du) then begin so1:=10+so1-so2-du; du:=1; end else begin so1:=so1-so2-du; du:=0; end; str(so1,tam); tru:=tam+tru; end; while (tru[1]=’0′) and (length(tru)>1) do delete(tru,1,1); end; BEGIN clrscr; write(‘Nhap so thu nhat:’); readln(s1); write(‘Nhap so thu hai:’); readln(s2); write(tru(s1,s2)); readln END.
uses crt;
var s1,s2:string;
function tru(x1,x2:string):string;
var tam:string[2];
du,i,so1,so2:byte;
begin
while length(x1)<>length(x2) do
if length(x1)<length(x2) then insert(‘0’,x1,1)
else insert(‘0’,x2,1);
du:=0; tru:=”;
for i:=length(x1) downto 1 do
begin
val(x1[i],so1); val(x2[i],so2);
if so1<(so2+du) then
begin
so1:=10+so1-so2-du;
du:=1;
end
else
begin
so1:=so1-so2-du;
du:=0;
end;
str(so1,tam);
tru:=tam+tru;
end;
while (tru[1]=’0′) and (length(tru)>1) do delete(tru,1,1);
end;
BEGIN
clrscr;
write(‘Nhap so thu nhat:’); readln(s1);
write(‘Nhap so thu hai:’); readln(s2);
write(tru(s1,s2));
readln
END.
Chúc bạn học tốt!