You are on page 1of 16

{Dùng app Pascal N – IDE để chạy chương trình, vì trong chương trình có sử dụng tiếng Việt có

dấu. }

{LẬP TRÌNH PASCAL: (ÔN THI HSG) CHƯƠNG TRÌNH NHẬP


VÀ XUẤT HÓA ĐƠN BÁN LẺ, GHI KẾT QUẢ DƯỚI ĐỊNH
DẠNG SỐ TIỀN VÀ ĐỌC SỐ TIỀN THÀNH CHỮ.}

uses crt;
procedure vietso(so:integer);
var z:integer;
begin
z:=so;
if (z>99) and (z<1000) then write(z);
if (z>9) and (z<100) then write('0',z);
if (z<10) then write('00',z);
end;
procedure docso(x:integer);
var tr,ch,dvi,l:integer;
begin
tr:= x div 100;
ch:= (x-100*tr) div 10;
dvi:= x mod 100 - 10*ch;
IF (wherex=13) then begin

Case tr of

1: write('Một');
2: write('Hai');
3: write('Ba');
4: write('Bốn');
5: write('Năm');
6: write('Sáu');
7: write('Bảy');
8: write('Tám');
9: write('Chín');
end;
if (tr<>0) then if (ch<>0) then write(' trăm ') else write('
trăm');

if (tr=0) then
case ch of
1:if (dvi<>0) then write('Mười ') else write('Mười');
2: write('Hai');
3: write('Ba');
4: write('Bốn');
5: write('Năm');
6: write('Sáu');
7: write('Bảy');
8: write('Tám');
9: write('Chín');
end
else
case ch of
0:if (tr<>0) and (dvi<>0) then write(' linh ');
1:if (dvi<>0) then write('mười ') else write('mười');
2: write('hai');
3: write('ba');
4: write('bốn');
5: write('năm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
if (ch<>1) and (ch<>0) then if (dvi<>0) then write(' mươi
') else write(' mươi');
if (tr+ch=0) then
case dvi of
1: if (ch<2) then write('Một') else write('mốt');
2: write('Hai');
3: write('Ba');
4: if (ch<2) then write('Bốn') else write('tư');
5: if (ch<1) then write('Năm') else write('lăm');
6: write('Sáu');
7: write('Bảy');
8: write('Tám');
9: write('Chín');
end
else

case dvi of
0: if (ch=0) and (tr=0) then write('không');
1: if (ch<2) then write('một') else write('mốt');
2: write('hai');
3: write('ba');
4: if (ch<2) then write('bốn') else write('tư');
5: if (ch<1) then write('năm') else write('lăm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
end
else
begin
Case tr of
0: begin
if (wherex>18) and (ch<>0) then write('không trăm ');
if (wherex>18) and (ch=0) and (dvi<>0) then
write('không trăm linh ') end;
1: write('một');
2: write('hai');
3: write('ba');
4: write('bốn');
5: write('năm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
if (tr<>0) then if (ch<>0) then write(' trăm ') else write('
trăm');
case ch of
0:if (tr<>0) and (dvi<>0) then write(' linh ');
1:if (dvi<>0) then write('mười ') else write('mười');
2: write('hai');
3: write('ba');
4: write('bốn');
5: write('năm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
if (ch<>1) and (ch<>0) then if (dvi<>0) then write(' mươi
') else write(' mươi');
case dvi of
0: if (ch=0) and (tr=0) then write('không');
1: if (ch<2) then write('một') else write('mốt');
2: write('hai');
3: write('ba');
4: if (ch<2) then write('bốn') else write('tư');
5: if (ch<1) then write('năm') else write('lăm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
end;
end;

var
vat,s,i,j,n,c,d,m,h,r,p,t,o,f,s1,s2,s3,s4,s5,s6,s7,s8,s9,p1,p2,
p3,p4,p5,p6,p7,p8,p9,v,m1,m2,n1,n3,n2,n4,n5,n6,k:int64
;
L,G: array [1..1000] of int64;
begin
clrscr;
s:=0;
write('Số mặt hàng: '); readln(n);clrscr; writeln;
for i:=1 to n do
begin
j:=i;
writeln('-) Mặt hàng (',i,'): ');
write('+) Số lượng: '); readln(l[i]);
write('+) Đơn giá: '); read(g[j]); p:=g[j]; gotoxy(13,wherey-
1);
if (p<1000) then write(p);
if (p>999) and (p<1000000) then begin
p1:= p div 1000;
p2:= p -1000*p1;
write(p1); write(','); vietso(p2); end;
if (p>999999) and (p<1000000000) then begin
p1:= p div 1000000;
p2:=(p-1000000*p1) div 1000;
p3:=p-1000000*p1-1000*p2;
write(p1); write(','); vietso(p2); write(','); vietso(p3); end;
if (p>999999999) then
begin p1:=p div 1000000000;
p2:=(p-p1*1000000000) div 1000000;
p3:=(p-1000000000*p1-1000000*p2) div 1000;
p4:= p- 1000000000*p1-1000000*p2-1000*p3;

if (p1<1000) then c:=1;


if (p1>999) and (p1<1000000) then c:=2;
if (p1>999999) and (p1<1000000000) then c:=3;
case c of
1: write(p1);
2: begin p5:=p1 div 1000; p6:=p1-1000*p5; write(p5,',');
vietso(p6); end;
3: begin p7:=p1 div 1000000; p8:=(p1-1000000*p7) div
1000; p9:=p1-1000000*p7-1000*p8;write(p7,',');
vietso(p8); write(',');vietso(p9); end;
end;
write(','); vietso(p2); write(','); vietso(p3); write(',');
vietso(p4); end;
write(' ₫');
s:= s+l[i]*p;
writeln; writeln;
end;
writeln('----------------------------'); writeln;
write('Thuế VAT: '); readln(vat);
gotoxy(1,wherey-1); writeln('Thuế VAT: ',vat,'%'); s:=
round(s+s*vat/100);
writeln;
write('TỔNG CỘNG: ');
if (s<1000) then write(s);
if (s>999) and (s<1000000) then begin
s1:= s div 1000;
s2:= s -1000*s1;
write(s1); write(','); vietso(s2); end;
if (s>999999) and (s<1000000000) then begin
s1:= s div 1000000;
s2:=(s-1000000*s1) div 1000;
s3:=s-1000000*s1-1000*s2;
write(s1); write(','); vietso(s2); write(','); vietso(s3); end;
if (s>999999999) then
begin
s1:=s div 1000000000;
s2:=(s-s1*1000000000) div 1000000;
s3:=(s-1000000000*s1-1000000*s2) div 1000;
s4:= s- 1000000000*s1-1000000*s2-1000*s3;
if (s1<1000) then d:=1;
if (s1>999) and (s1<1000000) then d:=2;
if (s1>999999) and (s1<1000000000) then d:=3;
case d of
1: write(s1);
2: begin s5:=s1 div 1000; s6:=s1-1000*s5; write(s5,',');
vietso(s6); end;
3: begin s7:=s1 div 1000000; s8:=(s1-1000000*s7) div
1000; s9:=s1-1000000*s7-1000*s8;write(s7,',');
vietso(s8); write(',');vietso(s9); end;
end;
write(','); vietso(s2); write(','); vietso(s3); write(',');
vietso(s4); end;

write(' ₫');

writeln;
writeln;
write('THÀNH TIỀN: ');
if (s<1000) then docso(s);
if (s>999) and (s<1000000) then
begin
n1:= s div 1000;
n2:= s mod 1000;
docso(n1); if (n2<>0) then write(' nghìn ') else write('
nghìn'); if (n2>0) then docso(n2);
end;
if (s>999999) and (s<1000000000) then
begin
n1:= s div 1000000;
n2:= (s mod 1000000) div 1000;
n3:= (s-(s div 1000000)*1000000) mod 1000;
docso(n1); if (n2+n3<>0) then write(' triệu ') else write('
triệu');
if (n2>0) then begin
docso(n2);if (n3<>0) then write(' nghìn ') else write('
nghìn'); end;
if (n3>0) then
docso(n3);
end;
if (s>999999999) then
begin
m1:= s div 1000000000;
m2:= s mod 1000000000;
n1:= m1 div 1000000;
n2:= (m1 mod 1000000) div 1000;
n3:= (m1-(m1 div 1000000)*1000000) mod 1000;
if (n1<>0) then begin docso(n1);

if (n2+n3<>0) then write(' triệu ') else write(' triệu'); end;


if (n2>0) then begin
docso(n2);if (n3<>0) then write(' nghìn ') else write('
nghìn'); end;

if (n3>0) then
docso(n3);
if (m2<>0) then write(' tỷ ') else write(' tỷ');

n4:= m2 div 1000000;


n5:= (m2 mod 1000000) div 1000;
n6:= (m2-(m2 div 1000000)*1000000) mod 1000;

if (wherex>90) then begin writeln; gotoxy(14,wherey);


end;
if (n4+n5+n6<>0) then begin
if (n4<>0) then begin docso(n4);

if (n5+n6<>0) then write(' triệu ') else write(' triệu'); end;


if (wherex>90) then begin writeln; gotoxy(14,wherey);
end;
if (n5>0) then begin
docso(n5);if (n6<>0) then write(' nghìn ') else write('
nghìn'); end;

if (n6>0) then
docso(n6);
end;
end;

write(' đồng.');
readln
end.

You might also like