Pascal
Modified: Wednesday, 22-12-2021 07:00 AM
Nhân xâu số nguyên (s>20 chữ số) với 1 số (0<N<=9)
var s,t:string;
n,i:byte;
function Check(s:string):boolean;
begin for i:=1 to length(s) do if not (s[i] in ['0'..'9']) then exit(false);
exit(true);
end;
procedure Nhan(s:string;n:byte);
var k,m:byte;
c:string;
begin
k := 0;
t := '';
for i:=length(s) downto 1 do begin
val(s[i],m);
m := m*n+k;
k := m div 10;
m := m mod 10;
str(m,c);
t := c+ t;
end;
if k>0 then begin
str(k,c);
t := c+t;
end;
end;
begin write('Nhap s: ');
readln(s);
while not Check(s) do begin write('Nhap lai s: ');
readln(s);
end;
write('Nhap n: ');
readln(n);
Nhan(s,n);
write(s,' x ',n,' = ',t);
readln;
end.