Nhập hai xâu tính tích hai xâu (xâu gồm toàn kí tự số) bằng pascal
2 câu trả lời
uses crt;
var s1,s2:string;
function nhan(a:string; b:string):string;
var i,j,nho,tam:longint; t:array[1..5000]of longint;
begin
nhan:='';
nho:=0; tam:=0;
for i:=length(a) downto 1 do
for j:=length(b) downto 1 do
inc(t[i+j-1],(ord(a[i])-48)*(ord(b[j])-48));
for i:=length(a)+length(b)-1 downto 1 do
begin
tam:=(t[i]+nho) div 10;
t[i]:=(t[i]+nho) mod 10;
nho:=tam;
end;
if (nho<>0) then nhan:=nhan+chr(ord(nho)+48);
for i:=1 to length(a)+length(b)-1 do nhan:=nhan+chr(ord(t[i])+48);
end;
begin
clrscr;
readln(s1);
readln(s2);
writeln(nhan(s1,s2));
readln
end.
uses crt;
var a, b: string;
function add(a, b: string): string;
var c: string;
sum, carry, i: longint;
begin
carry:=0; c:='';
while(length(a) < length(b)) do a:='0' + a;
while(length(b) < length(a)) do b:='0' + b;
for i:=length(a) downto 1 do
begin
sum:=ord(a[i]) - 48 + ord(b[i]) - 48 + carry;
carry:=sum div 10;
c:=chr(sum mod 10 + 48) + c;
end;
if(carry > 0) then c:='1' + c;
exit(c);
end;
function mul(a, b: string): string;
var sum, tmp: string;
m, i, j: longint;
begin
m:=-1; sum:='';
for i:=length(a) downto 1 do
begin
inc(m);
tmp:='';
for j:=1 to ord(a[i]) - 48 do tmp:=add(tmp,b);
for j:=1 to m do tmp:=tmp + '0';
sum:=add(tmp,sum);
end;
exit(sum);
end;
begin
clrscr;
readln(a);
readln(b);
writeln(mul(a, b));
readln;
end.