You are on page 1of 15

BI TP PASCAL Ch nht, 30/11/2008 12:23 pm BI TP PASCAL Chng 1.

Bi 1 Program Ca_dao; Begin Writeln('Trong dam gi dep bang sen,'); Writeln('La xanh bong trang lai chen nhi vang,'); Writeln('Nhi vang bong trang la xanh.'); Writeln('Gan bun ma chang hoi tanh mui bun'); Readln End. Bi 2 Program Tam_giac; Begin Writeln('*********'); Writeln(' *******'); Writeln(' *****'); Writeln(' ***'); Writeln(' *'); Readln End. Bi 3 Program Phep_Tru; Var so1,so2,hieu :Integer; Begin Writeln(' CHUONG TRINH THUC HIEN PHEP TRU SO HOC'); Writeln(' co toi da 4 ky so'); Write('-Nhap so thu nhat = '); Readln(so1); Write('-Nhap so thu hai = '); Readln(so2); hieu:= so1-so2; Writeln; Writeln; Writeln('-------------------------------'); Writeln; Writeln(' ',so1:4); Writeln(' - ',so2:4); Writeln(' -----'); Writeln(' = ',hieu:5); Readln End. Bi 4 Program Cuu_chuong_1; Var so :Integer; Begin Write('-Bang cuu chuong so may ?: '); Readln(so);

Writeln; Writeln; Writeln(' CHUONG TRINH BANG CUU CHUONG'); Writeln('-------------------------------'); Writeln; Writeln(so:2,' lan 1 = ',so*1:3); Writeln(so:2,' lan 2 = ',so*2:3); Writeln(so:2,' lan 3 = ',so*3:3); Writeln(so:2,' lan 4 = ',so*4:3); Writeln(so:2,' lan 5 = ',so*5:3); Writeln(so:2,' lan 6 = ',so*6:3); Writeln(so:2,' lan 7 = ',so*7:3); Writeln(so:2,' lan 8 = ',so*8:3); Writeln(so:2,' lan 9 = ',so*9:3); Writeln(so:2,' lan 10 = ',so*10:3); Readln End. Bi 5 rogram Cuu_chuong_2; Var so,i :Integer; Begin Write('-Bang cuu chuong so may ?: '); Readln(so); Writeln; Writeln; Writeln(' CHUONG TRINH BANG CUU CHUONG'); Writeln('-------------------------------'); Writeln; For i:=1 To 10 Do Writeln(so:2,' lan ',i:2,' = ',so*i:3); Readln End. Bi 6 Program Hinh_thang; Var a,b,h:Integer; S:Real; Begin Writeln('CHUONG TRINH TINH DIEN TICH HINH THANG'); Write('-Cho biet day ngan = '); Readln(a); Write('-Cho biet day dai = '); Readln(b); Write('-Cho biet chieu cao = '); Readln(h); S := 0.5 * (a + b) * h; Writeln('+Dien tich hinh thang = ',s:6:2,' met vuong'); Readln End. Bi 7 Program Tam_Giac; Var a,b,c:Integer; p,s:Real;

Begin Writeln('CHUONG TRINH TINH DIEN TICH TAM GIAC'); Write('-Cho biet canh thu nhat = '); Readln(a); Write('-Cho biet canh thu hai = '); Readln(b); Write('-Cho biet canh thu ba = '); Readln(c); p := 0.5 * (a + b + c); s := sqrt(p*(p-a)*(p-c)*(p-c)); Writeln('+Dien tich hinh tam giac = ',s:6:2,' met vuong'); Readln End. Bi 8 Program Hinh_cau; Var s:integer; r,v:Real; Begin Writeln('CHUONG TRINH TINH THE TICH HINH CAU'); Writeln('---------------------------------'); Write('Cho biet dien tich hinh tron = '); Readln(s); r:=Sqrt(s/4*3.1416); v:=4/3 * 3.1416 *r*r*r; Writeln('*The tich hinh cau la : ',V:6:2,' met khoi'); Readln End. Bi 9 Program Luc_hut; CONST g=6.672E-8; Var m1,m2,d,f:Real; Begin Writeln('CHUONG TRINH TINH LUC HUT GIUA 2 VAT'); Write('-Khoi luong m1 (gam) = '); Readln(m1); Write('-Khoi luong m2 (gam) = '); Readln(m2); Write('-Khoang cac giua 2 vat (Cm) = '); Readln(d); f := g * m1 * m2 / sqr(d); Writeln('+Luc hut giua 2 vat = ',f:6:2); Readln End. Bi 10 Program Pignet; Var Ten:String; Tuoi:Integer; lon,nho,tb,tl,cao,pig:Real; Begin Writeln('CHUONG TRINH TINH PIGNET'); Writeln('------------------------'); Write('-Cho biet ho ten : ');

Readln(ten); Write('-Cho biet tuoi : '); Readln(tuoi); Write('-Cho biet chieu cao : '); Readln(cao); Write('-Cho biet trong luong : '); Readln(tl); Write('-So do vong nguc luc hit vao = '); Readln(lon); Write('-So do vong nguc luc tho ra = '); Readln(nho); tb := 0.5 * (lon-nho); pig := cao - (tb + tl); Writeln; Write('+Ong (Ba) : ',ten:24); Writeln(' , ',tuoi,' tuoi'); Writeln('+Co so do Pignet = ',pig:6:2); Readln End. Bi 11 Program Tinh_luong; Var Ten:String; nc,pc,tam:Integer; bl,hs,tt,cl:Real; Begin Writeln('CHUONG TRINH TINH LUONG'); Writeln('------------------------'); Write('-Cho biet ho ten : '); Readln(ten); Write('-Cho biet bac luong : '); Readln(bl); Write('-Cho biet ngay cong : '); Readln(nc); Write('-Cho biet he so trach nhiem : '); Readln(hs); Write('-Cho biet phu cap khu vuc = '); Readln(pc); Write('-Cho biet so tien da tam ung ky 1 = '); Readln(tam); tt := ((bl/30 * nc * hs)+pc); cl := tt - tam; Writeln; Writeln('+Ong (Ba) : ',ten:24); Writeln('+Tien luong trong thang = ',tt:10:2,' dong'); Writeln('+So tien con linh = ',cl:10:2,' dong'); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 12 Program Tinh_dien_tich; Var cv,canh,s:Real; Begin Writeln('TINH DIEN TICH LON NHAT CUA HINH CHU NHAT'); Writeln('-----------------------------------------');

Write('-Cho biet chu vi chu nhat : '); Readln(cv); canh:=cv / 4; s:=canh * canh; Writeln('-Chu vi hinh chu nhat = ',cv:10:2,' met'); Writeln('-Dien tich lon nhat se= ',s:10:2,' met vuong' ); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 13 Program Tam_thuc; Var a,b,c,x,p:Integer; Begin Writeln('TINH TAM THUC'); Writeln('-------------'); Write('-Nhap a= '); Readln(a); Write('-Nhap b= '); Readln(b); Write('-Nhap c= '); Readln(c); Write('-Nhap x= '); Readln(x); p:=((a*(x*x)) + (b*x) + c); Writeln('*Tri cua tam thuc = ',p); Writeln('Bam phim <Enter> de ket thuc'); Readln End. Bi 14 Program Tinh_do_dai_vec_to; Var x,y,z:Integer; l:Real; Begin Writeln('TINH CHIEU DAI VECTO'); Writeln('---------------------'); Writeln; Write('-Cho biet toa do X : '); Readln(x); Write('-Cho biet toa do Y : '); Readln(y); Write('-Cho biet toa do Z : '); Readln(z); l:= Sqrt(Sqr(x) + Sqr(y) + Sqr(z)); Writeln('+Chieu dai cua vecto = ',l:10:2); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 15 Program Tinh_Z; Var x,z:Real; Begin Writeln('TINH GIA TRI Z QUA SO THUC X'); Writeln('----------------------------');

Write('-Nhap tri x = '); Readln(x); z:=ln(x + abs(sin(2 * x))); Writeln('*Gia tri cua Z = ',z:10:2); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Chng 2. Bi 1 Program ten_bien; Begin Writeln('Ky tu : Ten bien khong duoc co khoang trong'); Writeln('$conso: Ten bien khong duoc co dau $ o dau'); Writeln('5so : Ten bien khong duoc co con so o dau'); Writeln('Do,Repeat: Khong duoc dung cac tu khoa de dat ten bien'); Writeln; Writeln(' Bam phim <Enter> de ve cua so soan thao'); Readln End. Bi 2 Program tinh_luong; Var Ten:String[24]; bl,nc,pc,thang:Integer; tl,hs:Real; Begin Writeln('CHUONG TRINH TINH LUONG'); Writeln('-----------------------'); Writeln; Write('-Cho biet thang : '); Readln(thang); Write('-Cho biet ho ten : '); Readln(ten); Write('-Cho biet bac luong : '); Readln(bl); Write('-Cho biet ngay cong : '); Readln(nc); Write('-Cho biet he so : '); Readln(hs); Write('-Cho biet phu cap : '); Readln(pc); Writeln; tl:=((bl/30)*nc*hs+pc); Writeln('+Tien luong thang : ',thang:2,', cua Ong/Ba : ',ten,' la = ',tl:8:2); Writeln(' Bam phim <Enter> de ve cua so soan thao'); Readln End. Bi 3 Program Vong_tron; Var Radius,s,cv :Real; Begin Writeln('TINH CHU VI, DIEN TICH VONG TRON'); Writeln('--------------------------------'); Write('-Cho biet ban kinh : '); Readln(Radius);

cv:=2*Pi*Radius; S:=Pi*Radius*Radius; Writeln; Writeln('+Chu vi vong tron = ',cv:10:2); Writeln('+Dien tich vong tron = ',s:10:2); Writeln; Writeln(' Bam phim <Enter> de tro ve cua so soan thao'); Readln End. Bi 4 Program Doi_do_F_C; Var f,c:Real; Begin Writeln('DOI DO FAHRENHEIT SANG CELCIUS'); Write('-Cho biet do Fahrenheit : '); Readln(f); c:=((f-32) * 5)/9; Writeln; Writeln(f:5:2,' do Fahrenheit doi sang do Celcius = ',c:5:2,#248); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 5 Program Doi_do_Mile_Km; Const Km_Mile=1.609344; Var m,k:Real; Begin Writeln('DOI MILE SANG Km'); Write('-Cho biet so Mile can doi: '); Readln(m); k:=m * Km_Mile; Writeln; Writeln(m:5:2,' dam Anh doi thanh = ',k:5:2,' Km'); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 6 Program Chu_so; Var n:Integer; Begin Writeln('XUAT CAC CHU SO CUA SO NGUYEN DUONG N'); Write('-Cho biet so nguyen: '); Readln(n); Writeln('So nguyen: ',n:5,' Co cac chu so sau'); Write(' ', n DIV 10000); n :=n MOD 10000; Write(' ', n DIV 1000); n :=n MOD 1000; Write(' ', n DIV 100); n :=n MOD 100;

Write(' ', n DIV 10); n :=n MOD 10; Write(' ',n); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 7 Program Cac_phep_toan; Var a,b,c,d,e,x,y,g,h,i:Integer; Begin Writeln('CAC PHEP TOAN'); Writeln('-------------'); Writeln; a:=124; b:=12; Writeln(a:3,' DIV ',b:2,' = ',a DIV b); Writeln(a:3,' MOD ',b:2,' = ',a MOD b); c:=12; d:=22; Writeln(c:2,' AND ',d:2,' = ',c AND d); Writeln(c:2,' OR ',d:2,' = ',c OR d); Writeln(c:2,' XOR ',d:2,' = ',c XOR d); x:=2; g:=x Shl 7; Writeln('g = ',x:2,' Shl 7 = ',g); x:=256; h:=x Shr 7; Writeln('h = ',x:2,' Shr 7 = ',h); i:=g+h; Writeln('i = g + h = ',i); Writeln('Lo(i) = ',Lo(i)); Writeln('Hi(i) = ',Hi(i)); Writeln('Swap(i) = ',Swap(i)); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 8 Program Diem_trung_binh; Var Ten:String[24]; Van,Toan,Ly,Sinh,NgoaiNgu,Tb:Real; Begin Writeln('DIEM TRUNG BINH'); Writeln('-------------'); Write('-Cho biet ho ten: '); Readln(ten); Write('-Cho biet diem mon Van: '); Readln(Van); Write('-Cho biet diem mon Toan: '); Readln(Toan); Write('-Cho biet diem mon Ly: '); Readln(Ly); Write('-Cho biet diem mon Sinh vat: ');

Readln(Sinh); Write('-Cho biet diem mon Ngoai ngu: '); Readln(NgoaiNgu); tb:=((Van * 3) + (Toan * 2) + (Ly * 2) + Sinh + NgoaiNgu) / 9; Writeln('+Hoc sinh: ',ten,' co diem trung binh = ',tb:6:2); Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 9 Program Tinh_gia_tri_hang_hoa; Var n:Integer; a,c,l:Real; Begin Writeln('TINH GIA TRI HANG HOA'); Writeln('---------------------'); Writeln; Write('-Cho biet gia goc tra ngay: '); Readln(a); Write('-Cho biet lai suat l%/nam: '); Readln(l); Write('-Cho biet so ngay tra cham: '); Readln(n); c:= a * (1 + n * l / 36000); Writeln('+Gia hang hoa tra cham = ',c:10:2,' dong'); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 10 Program Tinh_do_dai_vec_to; Var x,y,z:Integer; l:Real; Begin Writeln('TINH CHIEU DAI VECTO'); Writeln('---------------------'); Writeln; Write('-Cho biet toa do X : '); Readln(x); Write('-Cho biet toa do Y : '); Readln(y); Write('-Cho biet toa do Z : '); Readln(z); l:= Sqrt(Sqr(x) + Sqr(y) + Sqr(z)); Writeln('+Chieu dai cua vecto = ',l:10:2); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 11 Program Trung_binh; Var a,b,c:Integer; P,S:Real; Begin Writeln('TINH TRUNG BINH CONG,TRUNG BINH NHAN');

Writeln('------------------------------------'); Writeln; Write('-Nhap so thu nhat: '); Readln(a); Write('-Nhap so thu hai : '); Readln(b); Write('-Nhap so thu ba : '); Readln(c); S:=(a + b + c) / 3; P:=Exp((1 / 3) * Ln(a * b * c)); Writeln('*Trung binh cong cua 3 so= ',s:6:2); Writeln('*Trung binh nhan cua 3 so= ',p:6:2); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 12 Program Tinh_a_mu_b; Var a,b:Integer; p:Real; Begin Writeln('TINH TRI CUA A MU B'); Writeln('-------------------'); Writeln; Write('-Nhap so nguyen A: '); Readln(a); Write('-Nhap so mu B : '); Readln(b); P:=Exp(b * Ln(a)); Writeln('*Tri A mu B = ',p:10:2); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 13 Program Tinh_tong; Var n,tong:Integer; Begin Writeln('TINH TONG CUA N SO NGUYEN'); Writeln('-------------------'); Writeln; Write('-Nhap so nguyen N: '); Readln(n); tong:=(n * (n + 1) DIV 2); Writeln('*Tong tu 1 den N = ',tong); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 14 Program Tinh_tien; Var v:Integer; l,n:Real; Begin Writeln('TINH TIEN GUI NGAN HANG'); Writeln('-------------------');

Writeln; Write('-So tien gui = '); Readln(v); Write('-Lai suat = '); Readln(l); n:=(v * (1 + (l/100))); Writeln('*Neu gui: ',v,' dong, lai suat 1 nam= ',l:4:2,' %'); Writeln('*So tien lai trong 1 nam = ',Round(v*l/100),' dong'); Writeln('*Von + Lai trong 1 nam = ',Round(n),' dong'); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Bi 15 Program Gia_hang_hoa; Var f,a,pe,pc,r:Real; n,y,t:Integer; Begin Writeln('TINH GIA HANG HOA'); Writeln('-----------------'); Writeln; Write('-So tien vay = '); Readln(a); Write('-Lai suat vay Ngan hang = '); Readln(r); Write('-Thoi gian san xuat= '); Readln(y); Write('-So san pham thu duoc = '); Readln(n); Write('-Thoi gian luu kho = '); Readln(t); Write('-Phi ton luu kho = '); Readln(f); pe:=a/n; pc:=pe * (1 + r * (t + y) / 1200) + f * t; Writeln('*Gia xuat xuong = ',pe:10:2,' dong'); Writeln('*Gia ban de hoa von la : ',pc:10:2,' dong'); Writeln(' Bam phim <Enter> de ket thuc'); Readln End. Chng 3. Bi 1 Program Tinh_Gio_Phut_Giay; Var sogiay,gio,phut,giay:Integer; Begin Writeln('TINH GIO:PHUT:GIAY'); Writeln('------------------'); Write('-Nhap so giay can tinh: '); Readln(sogiay); gio:=sogiay DIV 3600; sogiay:= sogiay MOD 3600; phut:=sogiay DIV 60; giay:=sogiay MOD 60; Writeln; Writeln('KET QUA CHUYEN DOI');

Writeln('+Neu nhap vao: ',sogiay,' giay'); Writeln('+Doi thanh: ',gio,' gio, ',phut,' phut, ',giay,' giay'); Readln End. Bi 2 Program Doi_cho; Var so1,so2:Integer; Begin Writeln('DOI CHO 2 SO NGUYEN'); Writeln('-------------------'); Write('-Nhap so thu nhat: '); Readln(so1); Write('-Nhap so thu hai : '); Readln(so2); so1:=so1+so2; so2:=so1-so2; so1:=so1-so2; Writeln('SAU KHI CHUYEN CHO'); Writeln('+So thu nhat bay gio la: ',so1); Writeln('+So thu hai bay gio la : ',so2); Readln End. Bi 3 Program Phep_nhan_so_hoc; Var binhan,nhan:LongInt; donvi,chuc,tram:Integer; Begin Writeln('TRINH BAY PHEP NHAN SO HOC'); Writeln('-------------------------'); Write('-Nhap so bi nhan : '); Readln(binhan); Write('-Nhap vao so nhan: '); Readln(nhan); donvi:=nhan MOD 10; chuc:=(nhan DIV 10) MOD 10; tram:=nhan DIV 100; Writeln(binhan:15); Writeln('x':9,nhan:6); Writeln('----':15); Writeln(donvi*binhan:15); Writeln(chuc*binhan:14); Writeln(tram*binhan:13); Writeln('-------':15); Writeln(binhan*nhan:15); Readln End. Bi 4 Program Tinh_the_tich_hinh_cau; Var s,v,r:Real; Begin Writeln('TINH THE TICH HINH CAU KHI BIET DIEN TICH'); Writeln('-----------------------------------------'); Write('-Cho biet dien tich hinh cau: ');

Readln(s); r:= Sqrt(s/4*pi); v:=4/3*pi*r*r*r; Writeln('+The tich hinh cau la: ',v:10:4,' met khoi'); Readln End. Bi 5 Program Tinh_sin; Var goc:Integer; rad,x:Real; Begin Writeln('TINH SIN(X)'); Writeln('-----------'); Write('-Nhap vao mot goc: '); Readln(goc); rad:=(pi * goc) / 180; x:=sin(rad); Writeln('+Sin(',goc:2,') = ',x:10:8); Readln; End. Bi 6 Program Ma_ASCII; Var kytu:Char; Begin Writeln('TIM MA ASCII CUA KY TU'); Writeln('----------------------'); Write('-Nhap vao mot ky tu: '); Readln(kytu); Writeln('+Ma ASCII cua ky tu: ',kytu,' la: ',Ord(kytu)); Readln End. Bi 7 Program Ky_tu; Var ma:Byte; Begin Writeln('TIM KY TU KHI BIET MA ASCII'); Writeln('--------------------------'); Write('-Cho biet ma ASCII: '); Readln(ma); Writeln('+Ky tu cua ma ASCII: ',ma:2,' la: ',Chr(ma)); Readln End. Bi 8 Program Doi_chu_thuong_ra_chu_HOA; Var ch,c1,c2:Char; Begin Writeln('DOI CHU THUONG RA CHU HOA'); Writeln('-------------------------'); Write('-Nhap mot ky tu bat ky: '); Readln(ch); c1:=upcase(ch); c2:=chr(ord(ch)-32);

Writeln('+Cach thu nhat, dung ham Upcase: ',c1); Writeln('+Cach thu hai,khong dung ham Upcase: ',c2); Readln End. Bi 9 Program Doi_chu_HOA_ra_chu_thuong; Var ch,c:Char; Begin Writeln('DOI CHU HOA RA CHU THUONG'); Writeln('-------------------------'); Write('-Nhap mot chu HOA bat ky: '); Readln(ch); c:=chr(ord(ch)+32); Writeln('+Doi ra chu thuong la: ',c); Readln End. Bi 10 Program Xuat_chuoi; Var ch:String; Begin Writeln('XUAT 5 LAN CHUOI VUA NHAP'); Writeln('-------------------------'); Write('-Nhap vao mot chuoi bat ky: '); Readln(ch); Write(ch,', ',ch,', ',ch,', ',ch,', ',ch); Readln End. Bi 11 Program Chu_ky_con_lac; Const g=918; Var l,t:Real; Begin Writeln('TINH CHU KY DAO DONG CON LAC DON'); Writeln('-----------------------'); Write('-Cho biet chieu dai con lac: '); Readln(l); t:=2*pi*sqrt(l/g); Writeln('+Chu ky dao dong dieu hoa cua con lac: ',t:10:3); Readln; End. Bi 12 Program Luc_hap_dan; Const gama=6.673E-8; Var m1,m2,f,d:Real; Begin Writeln('TINH LUC HAP DAN GIUA 2 VAT'); Writeln('----------------------'); Write('-Khoi luong vat thu nhat: '); Readln(m1); Write('-Khoi luong vat thu hai : ');

Readln(m2); Write('-Khoang cach 2 vat: '); Readln(d); f:=gama*m1*m2/sqr(d); Writeln('+Luc hap dan giua 2 vat= ',f:10:3); Readln End. Bi 13 Program Tinh_khoang_cach; Var a,b,c,d,x,y:Real; Begin Writeln('TINH KHOANG CACH TU 1 DIEM DEN DUONG THANG'); Writeln('------------------------------------------'); Write('-Nhap he so a= '); Readln(a); Write('-Nhap he so b= '); Readln(b); Write('-Nhap he so c= '); Readln(c); Write('-Nhap toa do x= '); Readln(x); Write('-Nhap toa do y= '); Readln(y); d:=((a*x) + (b*y) + c) / Sqrt(Sqr(a) + Sqr(b)); Writeln('+Khoang cach tu diem I den duong thang la: ',d:10:2); Readln End. Bi 14 Program Tach_so; Var n:Integer; x,p:Real; Begin Writeln('TACH MOT SO NGUYEN THANH 2 SO'); Writeln('-----------------------------'); Write('-Nhap mot so: '); Readln(n); x:=2*n/3; Write('+Con so: ',n,' tach thanh so: ',x:6:2); Writeln(' va so: ',(n-x):6:2); Readln End. Nam Duy Nguyen (suu tam)

You might also like