Procedure GPTB2; Var Delta: real; Begin Delta:=sqr(b)-4*a*c; If Delta<0 then Writeln('Phuong trinh vo nghiem.') Else If Delta=0 then Begin Write('Phuong trinh co nghiem kep : '); Write('x1,2=',-b/(2*a):8:2); End Else Begin x1:=(-b+sqrt(Delta))/(2*a); x2:=(-b-sqrt(Delta))/(2*a); Writeln('Phuong trinh co 2 nghiem phan biet la :'); Writeln('X1=',x1:8:2,', X2=',x2:8:2); End; End;
BEGIN Writeln(' Giai Phuong Trinh Bac Hai Voi Cac He So :'); Nhapabc(a,b,c); If a<>0 then GPTB2 Else Writeln(' Khong phai phuong trinh bac hai '); Readln ; END .
Tất cả các bài tập kiểu mảng:
Code:
{In Mang}
var A:array[1..100] of integer; tong,j,min,max,maxd,csmaxd,i,csmin,csmax,tg,n,tongle,tongchan,demam,demduong,demchan,demle:integer; tb:real; begin writeln('nhap so phan tu: ');readln(n); for i:=1 to n do begin writeln('gia tri phan tu thu ',i,':= '); readln(a[i]); end; readln; for i:=1 to n do write(a[i]:4); readln;
{Day Tang Dan} { for i:=1 to (n-1) do for j:=i+1 to n do if a[i]>a[j] then begin tg:=a[i]; a[i]:=a[j]; a[j]:=tg; end; for i:=1 to n do write(a[i]:4); readln; }
{Day Giam Dan} { for i:=1 to (n-1) do for j:=i+1 to n do if a[i]<a[j] then begin tg:=a[i]; a[i]:=a[j]; a[j]:=tg; end; for i:=1 to n do write(a[i]:4); readln; }
{Gia Tri Lon Nhat-Nho Nhat}
max:=a[1]; csmax:=1; for i:=1 to n do if max<a[i] then begin max:=a[i]; csmax:=i; end; writeln('phan tu lon nhat la: ',max,', chi so la: ',csmax); min:=a[1]; csmin:=1; for i:=1 to n do if min>a[i] then begin min:=a[i]; csmin:=i; end; writeln('phan tu be nhat la: ',min,', chi so la: ',csmin); readln;
{Tinh Tong-Trung Binh Cong}
tong:=0; for i:=1 to n do begin tong:=tong+a[i]; tb:=tong/n; end; writeln('tong cua cac phan tu la: ',tong:6); writeln('trung binh cong cua cac phan tu la: ',tb:6:2); readln;
{Tong cac so chan-le}
tongchan:=0; tongle:=0; for i:=1 to n do begin if a[i]>0 then tongchan:=tongchan+a[i]; if a[i]<0 then tongle:=tongle+a[i]; end; writeln('tong cac so chan:= ',tongchan); writeln('tong cac so le:= ',tongle); readln;
{Tong Cac so am-duong}
demduong:=0; demam:=0; for i:=1 to n do begin if a[i]>0 then demduong:=demduong+1; if a[i]<0 then demam:=demam+1; end; writeln('co tat ca ',demduong,' so duong'); writeln('co tat ca ',demam,' so am'); readln;
{Co bao nhieu so chan-le}
demchan:=0; demle:=0; for i:=1 to n do begin if (a[i] mod 2=0) and (a[i]<>0) then demchan:=demchan+1; if (a[i] mod 2=1) or (a[i] mod 2=-1) then demle:=demle+1; end; writeln('co tat ca ',demchan,' so chan'); writeln('co tat ca ',demle,' so le'); readln;
{Phan tu duong dau tien-cuoi cung}
i:=1; while (i<=n) and (a[i]<0) do i:=i+1; if i>n then writeln('khong co phan tu duong dau tien') else writeln('phan tu duong dau tien la',a[i]:4,', chi so la: ',i:2); i:=n; while (i>=1) and (a[i]<0) do i:=i-1; if i<1 then writeln('khong co phan tu duong cuoi cung') else writeln('phan tu duong cuoi cung la: ',a[i]:4,', chi so la: ',i:2); readln;
{Phan tu am dau tien-cuoi cung}
i:=1; while (i<=n) and (a[i]>=0) do i:=i+1; if i>n then writeln('khong co phan tu am dau tien') else writeln('phan tu am dau tien la',a[i]:4,', chi so la: ',i:2); i:=n; while (i>=1) and (a[i]>=0) do i:=i-1; if i<1 then writeln('khong co phan tu am cuoi cung') else writeln('phan tu am cuoi cung la: ',a[i]:4,', chi so la: ',i:2); readln;
{Phan tu chan dau tien-cuoi cung}
i:=1; while (i<=n) and (a[i] mod 2=1) do i:=i+1; if (i>n) or (i=0) then writeln('khong co phan tu chan dau tien') else writeln('phan tu chan dau tien la: ',a[i]:4,', chi so la: ',i:2); i:=n; while (i>=1) and (a[i] mod 2=1) do i:=i-1; if i<1 then writeln('khong co phan tu chan cuoi cung') else writeln('phan tu chan cuoi cung la: ',a[i]:4,', chi so la: ',i:2); readln;
{Phan tu le dau tien-cuoi cung}
i:=1; while (i<=n) and (a[i] mod 2=0) do i:=i+1; if i>n then writeln('khong co phan tu le dau tien') else writeln('phan tu le dau tien la: ',a[i]:4,', chi so la: ',i:2); i:=n; while (i>=1) and (a[i] mod 2=0) do i:=i-1; if i<1 then writeln('khong co phan tu le cuoi cung') else writeln('phan tu le cuoi cung la: ',a[i]:4,', chi so la: ',i:2); readln;
{Tim so duong be nhat}
i:=1; while(i<=n) and (a[i]<=0) do i:=i+1; if i>n then write('khong co phan tu duong be nhat') else begin if a[i]>0 then maxd:=a[i]; csmaxd:=i; for i:=csmaxd to n do if (a[i]<=maxd) and (a[i]>0) then begin maxd:=a[i]; csmaxd:=i; end; write('co so duong be nhat: ',maxd,', chi so: ',csmaxd); end; readln; writeln;
writeln('nhan enter de tro lai'); readln; end.
Tất cả các bài tập kiểu xâu:
Code:
{Nhap xau-in xau dao}
var st:string; max,i,n,k,j,demkitu,demtu:integer; ch:char; a:string; dem:array['A'..'Z'] of integer; begin writeln('xau can nhap la:'); readln(st) ; writeln('xau dao cua xau tren la:'); for i:=length(st) downto 1 do write(st[i]); readln; writeln;
{so lan xuat hien cua ki tu-ki tu xuat hien nhieu lan nhat}
for i:=1 to length(st) do st[i]:=upcase(st[i]); for ch:='A' to 'Z' do dem[ch]:=0; for i:=1 to length(st) do if (st[i]>='A') and (st[i]<='Z') then dem[st[i]]:=dem[st[i]]+1; for ch:='A' to 'Z' do if dem[ch]>=1 then writeln('ki tu ',ch,' xuat hien ',dem[ch],' lan'); max:=0; for ch:='A' to 'Z' do if dem[ch]>=max then max:=dem[ch]; for ch:='A' to 'Z' do if dem[ch]=max then writeln('ki tu ',ch,' xuat hien nhieu lan nhat, voi ',max,' xuat hien'); readln; writeln;
{chuyen ki tu thanh hoa-thuong}
writeln('xau duoc chuyen thanh ki tu hoa:'); for i:=1 to length(st) do st[i]:=upcase(st[i]); for i:=1 to length(st) do write(st[i]); readln; writeln('xau duoc chuyen thanh ki tu thuong:'); for i:=1 to length(st) do if (st[i]>='A') and (st[i]<='Z') then st[i]:=chr(ord(st[i])+32); for i:=1 to length(st) do write(st[i]); readln; writeln;
{kiem tra xau Palidrom}
a:=''; for i:= length(st) downto 1 do a:=a+st[i]; if a=st then write('xau vua nhap la xau Palidrom') else write('xau vua nhap khong la xau Palidrom'); readln; writeln;
{chuan hoa xau}
while st[i]=' ' do delete(st,1,1); while st[length(st)]=' ' do delete(st,length(st),1); k:=pos(' ',st); while k>0 do begin delete(st,k,1); k:=pos(' ',st); end; writeln('xau da duoc chuan hoa:'); for i:=1 to length(st) do write(st[i]); readln; writeln;
{so tu co trong xau}
demtu:=1; for i:=1 to length(st) do for j:=i+1 to length(st) do if st[i]=' ' then begin demtu:=demtu+1; i:=j; end; writeln('xau co ',demtu,' tu'); readln; writeln;
{xau viet hoa ki tu dau tien cua moi tu}
writeln('xau viet dung chinh ta la: '); st[1]:=upcase(st[1]); for i:=1 to length(st) do if st[i]=' ' then begin st[i+1]:=upcase(st[i+1]); end; for i:=1 to length(st) do write(st[i]); readln; writeln;
write('nhan enter de tro lai'); readln; end.
Bài tập kiểu tệp:
Code:
var tep1,tep2:text; i,n:integer; th,lt,tb:real; begin assign(tep1,'E:\a.txt'); rewrite(tep1); write('nhap so luong hoc sinh: ');readln(n); for i:=1 to n do begin writeln('diem hoc sinh thu ',i,':'); write('diemm li thuyet: ');readln(lt); write('diem thuc hanh: '); readln(th); write(tep1,lt:6:1,th:6:1); end; close(tep1); assign(tep2,'E:\b.txt'); rewrite(tep2);reset(tep1); i:=1; while not eof(tep1) do begin read(tep1,lt,th); tb:=(lt+th*2)/3; writeln('diem trung binh hoc sinh thu ',i,': ',tb:6:1); writeln(tep2,'diem trung binh hoc sinh thu ',i,': ',tB:6:1); i:=i+1; end; close(tep2); writeln('nhan enter de ket thuc'); readln; end.
Bài tập về tam giác:
Code:
var xa,xb,xc,ya,yb,yc,a,b,c,s:real; DE,CA,VU:BOOLEAN;
FUNCTION kcach(x1,x2,y1,y2:real):real; begin kcach:=sqrt(sqr(x1-x2)+sqr(y1-y2)); end;
FUNCTION dt(a,b,c:real):real; var p:real; begin p:=(a+b+c)/2; dt:=sqrt(p*(p-a)*(p-b)*(p-c)); end;
FUNCTION kiemtra(a,b,c:real): boolean; var ketqua: boolean; begin ketqua:=False; if (a+b>c) and (a+c>b) and (b+c>a) then ketqua:=True; kiemtra:=ketqua; end;
PROCEDURE Tinh_chat(a,b,c : real; Var deu,can,vuong:boolean); Begin Deu:=False; Can:=false; Vuong:= False; IF (a=b) or (b=c) or (a=c) then Can:= True; if (a=b) and (b=c) then Deu:=True; IF (a*a=b*b+c*c) OR (b*b=a*a+c*c) OR (c*c=a*a+b*b) Then Vuong:=True; end;
BEGIn
write('nhap toa do dinh A: ' );readln(xa,ya); write('nhap toa do dinh B: ');readln(xB,yb); write('nhap toa do dinh C: ');readln(xc,yc); a:=Kcach(xb,xc,yb,yc); b:=kcach(xc,xa,yc,ya); c:=kcach(xa,xb,ya,yb); if kiemtra(a,b,c) then begin s:=dt(a,b,c); writeln('do dai canh a= ',a:8:2); writeln('do dai canh b= ',b:8:2); writeln('do dai canh c= ',c:8:2); writeln('Chu vi = ',(a+b+c):9:2); writeln('dien tich = ',s:9:2); tinh_chat(a,b,c,de,ca,vu); if de then writeln('DAY LA TAM GIAC DEU ') ELSE if ca then writeln('DAY LA TAM GIAC CAN ') ELSE IF VU then writeln('DAY LA TAM GIAC VUONG '); if not(de) and not(ca) and not(vu) then writeln('DAY LA TAM GIAC THUONG '); end else writeln('khong ton tai tam giac');
readln; end.
teobaoloc
Posts : 1
Points : 3
Thanked : 0
>
Thú 3D
•»»-»alliga11«-««•
Posts : 1 Points : 3 Thanked : 0
Tiêu đề: Re: Tổng hợp bài tập pascal 11 (có đáp án) Mon Sep 26, 2011 1:37 pm
quá dữ. toàn những câu lệnh mới và hay. Cần phải học tập thêm
hyunjin
Posts : 46
Points : 178
Thanked : 4
Sinh Nhật : 25/09/1994
Tuổi : 29
Nick chat : the_gj0j_k0_ngu0j
>
Thú 3D
•»»-»beaver«-««•
Posts : 46 Points : 178 Thanked : 4 Sinh Nhật : 25/09/1994 Tuổi : 29 Nick chat : the_gj0j_k0_ngu0j
Tiêu đề: Re: Tổng hợp bài tập pascal 11 (có đáp án) Tue Sep 27, 2011 7:39 am
lúc học giải pt thì đã học chương trình con đâu anh.
Sponsored content
>
Thú 3D
•»»-»«-««•
Tiêu đề: Re: Tổng hợp bài tập pascal 11 (có đáp án)