Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 29 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
29
Dung lượng
276 KB
Nội dung
Thư Viện Các Dạng Bài Tập Pascal của Tin Học 11 - Phần 3 Program Chu_Chay; Uses Crt; Const a='Nha sach Minh Khai, 249 Nguyen Thi Minh Khai, Quan 1, Tp Ho Chi Minh '; b='Tel: 8 331 124, 9 250 590 '; c='Chuyen phat hanh cac giao trinh tin hoc phuc vu hoc sinh, sinh vien'; d='Chan thanh cam on quy doc gia'; Function Lap(Kt:Char; N:Integer): String; Var Tam:String; K:Integer; Begin Tam:=' '; For K:=1 To N Do Tam:=Tam+Kt; Lap:=Tam; End; { } Procedure WriteXY(X,Y:Integer; St:String); Begin GotoXY(X,Y); Write(St); End; { } Function Min(a,b:Integer):Integer; Begin If a < b Then Min:=a Else Min:=b; End; { } Procedure Chuchay(St:String); Var k:Integer; Tin:String; Begin Tin:=Lap(' ',68)+'<<' +St+' '; For k:=1 To Length(Tin) Do Begin TextColor(k MOD 16); WriteXY(6,8,Copy(Tin,k,Min(68,Length(Tin)-k+1))); Delay(100); End; End; { } Procedure Khung(x1,y1,x2,y2:Integer); Var k:Integer; Begin TextColor(14); WriteXY(x1,y1,#201); For k:=x1+1 To x2-1 Do Write(#205); Write(#187); WriteXY(x1,y2,#200); For k:=x1+1 To x2-1 Do Write(#205); Write(#188); For k:=y1+1 To y2-1 Do Begin WriteXY(x1,k,#186); WriteXY(x2,k,#186); End; End; { } BEGIN TextBackGround(1); ClrScr; TextColor(3+Blink); GotoXY(30,4); Writeln('NAM HOC 1999 -2000'); Khung(5,7,75,9); Repeat Chuchay(a); Chuchay(b); Chuchay(c); Chuchay(d); Until KeyPressed; END. Program Chuoi_Doi_Xung; Var St:String; i,l:Byte; Begin Writeln('CHUOI DOI XUNG'); Writeln(' '); Write('-Nhap chuoi: '); Readln(St); l:=Length(St); i:=1; While (i < l Div 2) And (St[i] = St[l-i+1]) Do Begin i:=i+1; If i < (l Div 2) Then Writeln('+Chuoi nay doi xung') End; While (i < l Div 2) And (St[i] <> St[l-i+1]) Do Begin i:=i+1; If i < (l Div 2) Then Writeln('+Chuoi nay khong doi xung') End; Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. 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. !" 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. "#$ 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-b)*(p-c)); Writeln('+Dien tich hinh tam giac = ',s:6:2,' met vuong'); Readln End. %& '()*"+, 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. -& './ 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. 0& 12 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. 3& 4 !5 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. %678#9+:;<: Program Cong_giay; Var gio,phut,giay,them:Integer; Begin Writeln('CONG THEM GIAY VAO GIO HIEN HANH'); Writeln(' '); Writeln('Nhap vao gio:phut:giay hien hanh'); Write('-Gio : '); Readln(gio); Write('-Phut: '); Readln(phut); Write('-Giay: '); Readln(giay); Write('-Cho biet so giay muon cong them: '); Readln(them); If (giay+them) < 60 Then giay:=giay+them Else Begin giay:=((giay+them)-60); phut:=phut+1; If phut >=60 Then Begin phut:=phut-60; gio:=gio+1; End; End; Writeln; Writeln('+Sau khi cong them so giay vao, gio moi la:'); Writeln(' ',gio,' : ',phut,' : ',giay); Writeln; Writeln('Bam phim <Enter> de ket thuc'); Readln End. %=;$>?"@;5 Program Doan_so; Var tren,duoi,giua:Integer; chon:Word; Begin tren:=100; duoi:=1; While duoi < tren Do Begin Writeln('DOAN SO BAN DANG NGHI TRONG DAU'); Writeln(' '); giua:=(tren+duoi) Div 2; Writeln('-So cua ban Ty: ',giua); Writeln('-Neu go so 0 se ngung'); Writeln('-Neu ban Ty noi so ',giua,' nho hon thi ban Teo go 1 '); Write('-Neu ban Ty noi so ',giua,' lon hon thi ban Teo go 2 '); Readln(chon); If chon = 0 Then exit; If chon = 1 Then duoi:=giua Else tren:=giua End; Readln End. %=AA>8 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. %=AA> Program Doi_cho; Var so1,so2:Integer; (* *) PROCEDURE Doi(Var n,m:Integer); Var tam:Integer; Begin tam:=n; n:=m; m:=tam; End; (* *) BEGIN Writeln('DOI CHO 2 SO'); Writeln('Dung thu tuc'); Writeln(' '); Write('-Nhap so thu nhat: '); Readln(so1); Write('-Nhap so thu hai: '); Readln(so2); Writeln('================='); Writeln(' Truoc khi doi cho'); Writeln('+So thu nhat = ',so1); Writeln('+So thu hai = ',so2); Writeln(' Sau khi doi cho'); Doi(so1,so2); Writeln('*So thu nhat : ',so1); Writeln('*So thu hai : ',so2); Writeln; Write(' Bam phim <Enter> de ket thuc '); Readln END. %=A.<";" Program Doi_chu_hoa; Var Chuoi:String; (* *) PROCEDURE Doi(Var St:String); Var i:Byte; Begin For i:=1 To Length(St) Do St[i]:=Upcase(St[i]); End; (* *) BEGIN Writeln('DOI CHU THUONG RA CHU HOA'); Writeln(' Dung thu tuc'); Writeln(' '); Write('-Nhap mot chuoi ky tu : '); Readln(Chuoi); Writeln; Doi(Chuoi); Writeln('+Doi ra chu hoa = ',chuoi); Writeln; Write(' Bam phim <Enter> de ket thuc '); Readln END. %=A7>"B"22 Program Doi_nhiet_do; Var t:Real; tiep:Char; (* *) FUNCTION Doi(x:Real):Real; Begin Doi:=((9*x/5) + 32); End; (* *) BEGIN Repeat Writeln('DOI DO BACH PHAN SANG DO FARENHEIT'); Writeln(' Su dung ham'); Writeln(' '); Write('-Nhap do bach phan: '); Readln(t); Writeln('*Doi sang do Farenheit = ',Doi(t):6:2); Writeln; Write('-Co tiep tuc khong ? (c/k) '); Readln(tiep); Until tiep='k' ; END. %%=A7>"2'> 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. %-=ACD2>"EC 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. %0=A:";5 Program Thu_trong_tuan; Var d:1 31; m:1 14; y:1900 2000; a:Integer; Begin Writeln('DOI NGAY RA THU TRONG TUAN'); Writeln(' Lich the ky 20'); Writeln(' '); Repeat Write('-Ngay ( so 0 de ngung): '); Readln(d); If d = 0 Then Exit; Write('-Thang: '); Readln(m); Write('-Nam: '); Readln(y); If m < 3 Then Begin m:=m+12; Dec(y); End; a:=d+2*m+(3*(m+1) Div 5)+y+(y Div 4) + 1; a:=a Mod 7; Case a Of 0 :Begin Write('Ngay ',d:2,' / ',m:2,' / ',y:4); Writeln(' la ngay Thu Bay'); End; 1 :Begin Write('Ngay ',d:2,' / ',m:2,' / ',y:4); Writeln(' la ngay Chu Nhat'); End; Else Begin Write('Ngay ',d:2,' / ',m:2,' / ',y:4); Writeln(' la ngay ',a); End; End; Until d=0; End. %3=A6>"% Program Doi_he_so; Var n:Integer; (* *) FUNCTION Doi(so:Integer):String; Const ky_so:Array[0 15] Of Char =('0','1','2','3','4','5', '6','7','8','9','A','B','C','D','E','F'); Var tam1:Integer; tam2:String; Begin tam1:=Hi(so); tam2:=ky_so[tam1 Shr 4] + ky_so[tam1 And $0F]; tam1:=Lo(so); Doi:=tam2+ky_so[tam1 Shr 4] +Ky_so[tam1 And $0F] End; (* *) BEGIN Repeat Writeln('DOI SO HE 10 SANG HE 16'); Writeln(' Su dung ham '); Writeln(' '); Writeln('Nhap mot so nguyen tu -32768 den 32767'); Write('neu nhap so 0 se ket thuc '); Readln(n); Writeln; Writeln('+So he 10 la = ',n); Writeln('+Doi sang he 16 la = ',Doi(n)); Writeln; Until n=0; END. -6=A6>"%F;G2H Program Doi_he_16; Var n,so,chuso:Integer; tiep:Char; Begin Writeln('DOI SO HE 10 SANG HE 16'); Writeln(' '); Repeat Write('-Nhap so he 10 = '); Readln(so); n:=4096; {16 luy thua 3} Write('+Ky so he 16= '); Repeat chuso:=so Div n; Case chuso Of 0 9:Write(chuso); 10 15:Write(chr(chuso + 55)); End; so:=so- n*(so Div n); n:=n Div 16; Until n=0; Writeln; Write('-Co thuc hien tiep khong ? (C/K) '); Readln(tiep); Until Upcase(tiep)='K'; Writeln; Writeln(' Bam phim <Enter> de ket thuc'); Readln End. -=A6>" Program Doi_so_he_2; Var n,so:Integer; tiep:Char; Begin [...]... chon 3 noi:'); Write(' -Noi thu nhat: '); Readln(ch1); Write(' -Noi thu hai: '); Readln(ch2); Write(' -Noi thu ba: '); Readln(ch3); ng3:=[ch1,ch2,ch3]; Ba:=ng1 * ng2 * ng3; Hai:=(ng1*ng2-ng3) + (ng2*ng3-ng1) + (ng3*ng1-ng2); Mot:=ng1 + ng2 +ng3; Writeln; Writeln('*Cac noi ma ca 3 nguoi deu chon: '); For i:=1 To 5 Do If i In Ba Then Den(i); Writeln; Writeln('*Noi chi co 2 nguoi chon: '); For i:=1 To 5... Writeln('1-Nguoi thu nhat chon 3 noi:'); Write(' -Noi thu nhat: '); Readln(ch1); Write(' -Noi thu hai: '); Readln(ch2); Write(' -Noi thu ba: '); Readln(ch3); ng1:=[ch1,ch2,ch3]; Writeln('2-Nguoi thu hai chon 3 noi:'); Write(' -Noi thu nhat: '); Readln(ch1); Write(' -Noi thu hai: '); Readln(ch2); Write(' -Noi thu ba: '); Readln(ch3); ng2:=[ch1,ch2,ch3]; Writeln( '3- Nguoi thu ba chon 3 noi:'); Write(' -Noi thu... Then Chuoikq := Copy(Chuoitk,4*Tram -3, 4)+' TRAM '+ Copy(Chuoitk,4*Chuc -3, 4) +' MUOI'; If (Tram > 0) And (Chuc 0) And (Donvi > 0) Then Chuoikq := Copy(Chuoitk,4*Tram -3, 4)+' TRAM '+ Copy(Chuoitk,4*Chuc -3, 4) +' MUOI '+ Copy(Chuoitk,4*Donvi -3, 4); If (Tram > 0) And (Chuc 0) And (Donvi = 5) Then Chuoikq := Copy(Chuoitk,4*Tram -3, 4)+' TRAM '+ Copy(Chuoitk,4*Chuc -3, 4) +' MUOI LAM'; Write('-Viet bang... End 199/Kiểm tra ngày: Program kt_ngay; CONST Ngay = [1 31 ]; Thang = [1 12]; Th31ngay: Set of byte = [1 ,3, 5,7,8,10,12]; BaoLoi : Array[1 3] Of String [30 ] =('-Ban nhap sai ngay, thang', '-Thang nay khong co ngay 31 ','-thang 2 khong co ngay nay'); TYPE NgayThang = RECORD Ng, Th : Byte; Nam : Word; End; VAR Nhatky : NgayThang; Loi : Array[1 3] Of Boolean; i : Byte; Nhuan : Boolean; BEGIN With Nhatky... ngay=1 31 ; thang=1 12; Var d:ngay; m:thang; y:Word; (* *) FUNCTION Nhuan(Nam:Word):Boolean; Begin If nam Mod 100 = 0 Then Nhuan:=(Nam Mod 400)=0 Else Nhuan:=(Nam Mod 4)=0; End; (* *) FUNCTION So_ngay(d:Ngay; m:Thang; Y:Word): Boolean; Var t1,t2,t3:Boolean; Begin t1:=(d =30 ) And (m=2); t2:=(d=29) And (m=2) And (Not Nhuan(y)); t3:=(d =31 ) And (m in [2,4,6,9,11]); If t1 Or t2 Or t3 Then... 5) Then Chuoikq:=Copy(Chuoitk,4 * Chuc -3, 4)+' MUOI '+Chuoikq; If (Tram > 0) And (Chuc=0) And (Donvi=0) Then Chuoikq:=Copy(Chuoitk,4*Tram -3, 4)+' TRAM '; If (Tram > 0) And (Chuc = 0) And (Donvi > 0) Then Chuoikq := Copy(Chuoitk,4*Tram -3, 4)+' TRAM LINH '+ Copy(Chuoitk,4*Donvi -3, 4); If (Tram > 0) And (Chuc = 1) And (Donvi = 0) Then Chuoikq := Copy(Chuoitk,4*Tram -3, 4)+ 'TRAM MUOI'; If (Tram > 0) And (Chuc... Donvi -3, 4); If (Donvi = 5) And (Chuc = 0) Then Chuoikq :=Chuoikq + ' NAM'; If (Donvi = 5) And (Chuc > 0) Then Chuoikq := Copy(Chuoitk,4 * Chuc -3, 4)+' LAM'; If (Donvi = 5) And (Chuc = 1) Then Chuoikq := ' LAM'; If Chuc = 1 Then Chuoikq:='MUOI'+chuoikq; If (Chuc > 1) And (Donvi = 0) Then Chuoikq:=Copy(Chuoitk,4 * Chuc -3, 4)+' MUOI '; If (Chuc > 1) And (Donvi = 1) Then Chuoikq:=Copy(Chuoitk,4 * Chuc -3, 4)+'... of 1 5; Var ng1,ng2,ng3,Ba,Hai,Mot:DiaDiem; ch1,ch2,ch3,i:Byte; (* *) PROCEDURE Den(i:Byte); Begin Case i Of 1:Write('Da Lat '); 2:Write('Vung Tau '); 3: Write('Nha Trang '); 4:Write('Hue '); 5:Write('Ha Noi '); End; End; (* *) BEGIN ClrScr; Writeln('CHUONG TRINH THAM QUAN'); Writeln(' '); Writeln(' 1-Da Lat'); Writeln(' 2-Vung Tau'); Writeln(' 3- Nha Trang'); Writeln('... Then s:='muoi' Else s:=KS[sn[1]]+DV[Muoi]; If sn[2] = '5' Then s:=s+'lam' Else s:=s+KS[sn[2]]; End; 3: Begin s:=KS[sn[1]]+DV[Tram]; Case sn[2] Of '0' : If sn [3] '0' Then s:=s+'le'; '1' : s:=s+'muoi'; Else s:=s+KS[sn[2]]+DV[Muoi]; End; If (sn [3] ='5') And (sn[2] '0') then s:=s+'lam' Else s:=s+KS[sn [3] ]; End; End; Writeln(s); Writeln; Write(' Bam phim de ket thuc '); readln End 174/Đổi số... Write('-Nhap nam = '); Readln(Nam); Loi[1] := (NOT(Ng In Ngay)) OR (NOT (Th In Thang)); Loi[2] := (Ng = 31 ) AND (NOT (Th In Th31Ngay)); Nhuan := ((Nam Mod 4) = 0) AND ((Nam Mod 100) 0) OR ((Nam Mod 400) = 0); Loi [3] := ((Ng > 29) AND (Th = 2)) OR ((Ng = 29) AND (th = 2) AND (NOT Nhuan)); End; For i := 1 To 3 Do If Loi[i] Then Writeln(BaoLoi[i]); Readln END . '); Readln(ch3); ng3:=[ch1,ch2,ch3]; Ba:=ng1 * ng2 * ng3; Hai:=(ng1*ng2-ng3) + (ng2*ng3-ng1) + (ng3*ng1-ng2); Mot:=ng1 + ng2 +ng3; Writeln; Writeln('*Cac noi ma ca 3 nguoi deu chon:. Thư Viện Các Dạng Bài Tập Pascal của Tin Học 11 - Phần 3 Program Chu_Chay; Uses Crt; Const a='Nha sach Minh. '); Readln(ch2); Write(' -Noi thu ba: '); Readln(ch3); ng2:=[ch1,ch2,ch3]; Writeln(&apos ;3- Nguoi thu ba chon 3 noi:'); Write(' -Noi thu nhat: '); Readln(ch1);