Đọc số ra tiền trong Pascal

3 2.4K 23
Đọc số ra tiền trong Pascal

Đang tải... (xem toàn văn)

Thông tin tài liệu

Đổ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:=chu+a[tram]+' tram' Else chu:=chu+' khong tram'; Case chuc of 1:chu:=chu+' muoi'; 0:if donvi<>0 then chu:=chu+' le'; else chu:=chu+a[chuc]+' muoi'; End;{case} Case donvi of 1:if (chuc<>1) and (chuc<>0) then chu:=chu+' mot' else chu:=chu+ a[donvi]; 5:if chuc<>0 then chu:=chu+' lam' else chu:=chu+a[donvi]; else{case} IF donvi<>0 then chu:=chu+ a[donvi]; End;{case} doichu:=chu; end;{doichu} BEGIN a[1]:=' mot'; a[2]:=' hai'; a[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); chuso[1]:=upcase(chuso[1]); chuso:=chuso+' dong'; end; writeln(chuso); writeln; write('Tiep nua khong? (Y/N)'); tiep:=readkey; until upcase(tiep)='N'; end. . 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:=chu+a[tram]+' tram' . Đổ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; . 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

Ngày đăng: 12/07/2014, 11:00

Tài liệu cùng người dùng

Tài liệu liên quan