Đổi tiền ra chữ viết bằng Pascal
uses crt;
var
a:array[1 9] of string[5];
so:real;
ty,trieu,tram,nghin:0 999;
cty,ctrieu,ctram,cnghin:string[3];
chuso:string;
cso:string[30];
loi,l:integer;
tiep:char;
Function doichu(n:integer):string;
var
chu:string;
tram,chuc,donvi:0 9;
begin
tram:=n div 100;
chuc:=(n-tram*100) div 10;
donvi:=n-tram*100-chuc*10;
chu:='';
If tram<>0 Then
chu:=chưa[tram]+' tram'
Else
chu:=chứ khong tram';
Case chuc of
1:chu:=chứ muoí;
0:if donvi<>0 then chu:=chứ lé;
else chu:=chưa[chuc]+' muoí;
End;{case}
Case donvi of
1:if (chuc<>1) and (chuc<>0) then chu:=chứ mot' else chu:=chư a[donvi];
5:if chuc<>0 then chu:=chứ lam'
else chu:=chưa[donvi];
else{case}
IF donvi<>0 then chu:=chư a[donvi];
End;{case}
doichu:=chu;
end;{doichu}
BEGIN
a[1]:=' mot';
a[2]:=' haí;
Trang 2a[3]:=' ba';
a[4]:=' bon';
a[5]:=' nam';
a[6]:=' sau';
a[7]:=' bay';
a[8]:=' tam';
a[9]:=' chin';
Repeat
clrscr;
Write('Nhap so: ');readln(so);
if so=0 then chuso:='Khong dong'
else
begin
chuso:='';
str(so:12:0,cso);
ctram:=copy(cso,10,3);
cnghin:=copy(cso,7,3);
ctrieu:=copy(cso,4,3);
cty:=copy(cso,1,3);
val(cty,ty,loi);
val(ctrieu,trieu,loi);
val(cnghin,nghin,loi);
val(ctram,tram,loi);
if ty<>0 then chuso:=chuso+doichu(ty)+' ty';
if (ty<100) and (ty>=10) then delete(chuso,1,11);
if ty<10 then delete(chuso,1,14);
if trieu<>0 then chuso:=chuso+doichu(trieu)+' trieu';
if (ty=0) and (trieu<100) and (trieu>=10) then
delete(chuso,1,11);
if (ty=0) and (trieu<10) then delete(chuso,1,14);
if nghin<>0 then chuso:=chuso+doichu(nghin)+' nghin';
if (ty=0) and (trieu=0) and (nghin<100) and
(nghin>=10) then
delete(chuso,1,11);
if (ty=0) and (trieu=0) and (nghin<10) then
delete(chuso,1,14);
if tram<>0 then chuso:=chuso+doichu(tram);
delete(chuso,1,1);
Trang 3chuso[1]:=upcase(chuso[1]); chuso:=chusớ dong';
end;
writeln(chuso);
writeln;
write('Tiep nua khong? (Y/N)'); tiep:=readkey;
until upcase(tiep)='N';
end