DE THI PASCAL HP1 Director by:Luu Cong Hoan
BT 2.29.Giai PT ax+b>0
Program BT229;
Uses crt;
Var a,b,x:real;
Begin
clrscr;
writeln('Giai BPT dang ax+b>0');
write('Nhap vao a,b= '); readln(a,b);
if a=0 then
if b>0 then
writeln('Pt co vo so nghiem!')
else
write('Pt vo nghiem!');
if a<>0 then
begin
if a>0 then writeln('Pt co nghien la x> ',-b/a:0:4);
if a<0 then writeln('Pt co nghien la x< ',-b/a:0:4);
end;
readln
End.
BT 2.20.Giai BPT bac hai : ax^2+bx+c >0
Uses crt;
Var a,b,c,d,x1,x2:real;
Begin clrscr;
writeln('Giai bpt ax^2+bx+c>0');
write('Nhap vao a,b,c:'); readln(a,b,c);
d:=b*b-4*a*c;
if a>0 then
begin
if d<0 then writeln('BPT co vo so nghien thuc');
if d=0 then writeln('BPT co nghien la moi x khac ',-b/(2*a):0:2);
if d>0 then
begin
x1:=(-b-sqrt(d))/(2*a); x2:=(-b+sqrt(d))/(2*a);
writeln(' BPT co nghiem x<',x1:0:2,' x>',x2:0:2);
end;
end;
if a<0 then
begin
if d<=0 then writeln('BPT vo nghien!');
if d>0 then
begin
x1:=(-b+sqrt(d))/(2*a);
x2:=(-b-sqrt(d))/(2*a);
writeln('BPT co nghiem la: ',x1:0:2,' <x< ',x2:0:2);
end;
end;
if a=0 then
begin
if b=0 then
begin
if c>0 then writeln('BPT co vo so nghiem x thuoc R') else writeln('BPT vo nghiem');
end;
if b>0 then writeln('BPT co nghiem x >',-c/b:0:2);
if b<0 then writeln('BPT co nghiem x <',-c/b:0:2);
end;
readln
End.
BT 2.21.Giai PT bac 4: ax^4+bx^2+c =0 (a#0)
Uses crt;
Var a,b,c,d:real;
t1,t2:real;
Begin clrscr;
repeat
writeln('Giai pttp ax^4+bx^2+c=0 (a#0)');
write('nhap he so a,b,c='); readln(a,b,c);
until a<>0;
d:=b*b-4*a*c;
if d<0 then writeln('pt vo nghiem');
if d=0 then
begin
if a*b>0 then writeln('pt vo nghiem');
if a*b=0 then writeln('pt co 1 nghiem x=0');
if a*b<0 then writeln('pt co 2 nghiem x1=',-sqrt(-b/2/a):0:2,'; x2=',sqrt(-b/2/a):0:2);
end;
if d>0 then
begin
t1:=(-b-sqrt(d))/2/a; t2:=(-b+sqrt(d))/2/a;
if a>0 then
begin
if t2<0 then writeln('pt vo nghiem');
if t2=0 then writeln('pt co 1 nghiem x=0');
if t2>0 then
begin
if t1<0 then writeln('pt co 2 nghiem x1=',-sqrt(t2):0:2,'; x2=',sqrt(t2):0:2);
if t1=0 then writeln('pt co 3 nghiem x1=0; x2=',-sqrt(t2):0:2,'; x3=',sqrt(t2):0:2);
if t1>0 then
begin
writeln('pt co 4 nghiem x1=',-sqrt(t1):0:2,'; x2=',sqrt(t1):0:2);
writeln(' x3=',-sqrt(t2):0:2,'; x4=',sqrt(t2):0:2);
end;
end;
end;
if a<0 then
begin
if t1<0 then writeln('pt vo nghiem');
if t1=0 then writeln('pt co 1 nghiem x=0');
if t1>0 then
begin
if t2<0 then writeln('pt co 2 nghiem x1=',-sqrt(t1):0:2,'; x2=',sqrt(t1):0:2);
if t2=0 then writeln('pt co 3 nghiem x1=0; x2=',-sqrt(t1):0:2,'; x3=',sqrt(t1):0:2);
if t2>0 then
begin
writeln('pt co 4 nghiem x1=',-sqrt(t1):0:2,'; x2=',sqrt(t1):0:2);
writeln(' x3=',-sqrt(t2):0:2,'; x4=',sqrt(t2):0:2);
end;
end;
end;
end;
readln
End.
BT 2.22.Giai PT bac nhat 2 an :
ax by c
dx ey f
+ =
+ =
Var a,b,c,d,e,f,DT,Dx,Dy:real;
Begin
writeln(‘Giai HPT bac nhat 2 an so’);
write(‘Nhap cac he so a,b,c=’); readln(a,b,c);
write(‘Nhap cac he so d,e,f=’); readln(d,e,f);
DT:=a*e-b*d;
Dx:=c*e-b*f;
Dy:=a*f-c*d;
if DT=0 then
Begin
If Dx=Dy=0 then writeln(‘HPT co vo so nghiem!’);
If (Dx<>0) or (Dy<>0) then writeln(‘HPT vo nghiem!’);
End;
if DT<>0 then writeln(‘HPT co ng ! x=’,Dx/DT:0:2,’ y=’,Dy/DT:0:2);
readln
End.
BT 2.23. Cho 3 so thuc duong a,b,c.
a, Ton tai hay khong, mot tam giac nhan chung lam 3 canh.
b, Neu ton tai, xet tam giac do la vuong, nhon hay tu.
Var a,b,c:real;
Begin
write('Nhap vao 3 so bat ki a,b,c='); readln(a,b,c);
if (a>0) and (b>0) and (c>0) and (a+b>c) and (c+b>a) and (a+c>b) then
begin
writeln('Day la 3 canh cua mot tam giac');
if (a*a+b*b=c*c) or (a*a+c*c=b*b) or (c*c+b*b=a*a) then writeln('Day la tam giac vuong')
else begin
if (a*a+b*b>c*c) and (a*a+c*c>b*b) and (c*c+b*b>a*a) then
writeln('Day la tam giac nhon')
else writeln('Day la tam giac tu');
end;
end
else writeln('Day ko la 3 canh tam giac');
readln
End.
BT 2.26. Cho so tu nhien n(n<=1000);
a, Hoi n co bao nhieu chu so. b, Tinh tong cac chu so cua n.
c, Tim chu so dau tien, cuoi cung cua n.
Var n,:word;
Scs,Tcs,Csd,Csc:byte;
Begin
repeat
writeln(‘Cho so tu nhien n(n<1000)); readln(n);
until (n>0) and(n<1000);
Csc:=n mod 10;
Tcs:=0; Scs:=0;
repeat
Scs:=Scs+1;
Tcs:=Tcs+(n mod 10);
Csc:= n mod 10;
until n=0;
writeln(n, ‘co’,Scs,’so chu so’);
writeln(‘Tong cac chu so la’,Tcs);
writeln(‘Chu so dau la’,Csd,’;Chu so cuoi’,Csc);
readln
End.
BT 2.29. Nhap vao 1 day cac so nguyen tu ban phim cho den khi gap so 0,
Sau do tinh tong cac so duong, trung binh cong cac so am.
Var n,Tsd,Tsa:integer; d:byte;
Begin
writeln('Nhap vao 1 day cac so nguyen cho den khi gap so 0');
Tsd:=0; Tsa:=0; d:=0;
repeat
write('Nhap n='); readln(n);
if n>0 then Tsd:=Tsd+n;
if n<0 then
begin
Tsa:=Tsa+n;
inc(d);
end;
until n=0;
writeln('TongSoDuong la:',Tsd);
if d>0 then writeln('TrungBinhCong so am la:',Tsa/d:0:2)
else writeln(‘Khong co so am nao’);
readln
End.
BT 2.35. Cho so tu nhien h(1<h<25).Su dung ki tu ‘*’
in ra ma hinh tam giac can dac voi chieu cao h
Var i,j,h:byte;
Begin
writeln('In Tamgiac can boi * chieu cao h(1<h<25)');
repeat
write('Nhap chieu cao h(1<h<25):');
readln(h);
until (h>1) and (h<25);
for i:=1 to h do
begin
gotoxy(41-i,i); {41 48}
for j:=1 to 2*i-1 do write('*');
writeln;
end;
readln;
End.
BT 2.37. Btoan :”Tram trau tram co, trau dung an 5, trau nam an 3
lai nhai nghe hoa, ba con 1 bo”
Var d,n,ng:byte;
SoNg:word;
Begin
SoNg:=0;
writeln('Trau dung Trau nam Nghe hoa');
for ng:=1 to 100 do
for n:=1 to 34 do
for d:=1 to 20 do
if 5*d+3*n+ng/3=100 then
begin
writeln(d:4,n:4,ng:4);
inc(SoNg);
end;
if SoNg>0 then writeln('So nghiem Btoan la',SoNg)
else writeln(‘PT vo nghiem’);
readln
End.
BT 2.38. Tim nghiem ngduong PT:2x+5y=k, voi k nhap tu ban phim(k<=10000).
Var k,x,y,SoNg:word;
Begin
writeln('Giai pt 2x+5y=k,k nhap tu ban phim');
repeat
write('Nhap so tu nhien k(k<10000):');
readln(k);
until (k>0) and (k<10000);
SoNg:=0;
for x:=1 to Trunc(k/2) do
for y:=1 to Trunc(k/5) do
if 2*x+5*y=k then
begin
write('(',x,',',y,') ');
inc(SoNg);
end;
writeln;
if SoNg>0 then writeln('So nghiem nguyen duong PT la:',SoNg)
else writeln(‘PT vo nghiem nguyen duong’);
readln
End.
BT 2.39. Mot nguoi gui vao ngan hang so tien A dong.Lai xuat moi thang la 0.8%.
De co B dong(B>A), can phai gui it nhat bao nhieu thang ?
Const LS=0.008;
Var A,B:real; t:word;
Begin
writeln('BToan gui tien tiet kiem');
write('Co bao nhieu?'); readln(A);
write('Muon co bao nhieu?'); readln(B);
t:=0;
while A<B do
begin
A:=A*LS;
inc(t);
end;
writeln('Can gui it nhat la ',t,' thang');
writeln('Bam phim Enter de ket thuc!');
readln
End.
BT 2.40. Mot nguoi gui vao ngan hang so tien A dong ,loai co ki han 3 thang
(tron 3 thang tinh lai 1 lan) voi lai suat moi thang la 1.0%.
Hoi sau t thang nguoi do nhan duoc bao nhieu tien?
Const LS=0.01;
Var A: real;
i,t: word;
Begin
writeln('Lai suat gui tiet kiem co ky han');
write('Co bao nhieu?'); readln(A);
write('Gui trong bao lau(thang):'); readln(t);
for i:=1 to Trunc(t/3) do A:= A+3*0.01*A;
writeln('So tien co sau ',t,' thang la:',A:0:0);
readln
End.
{Sau du 3 thang moi duoc tinh lai, luc do lai suat duoc nhap vao von,
nghia la sau du 3 thang co A:=A+3*0.01*A. so lan duoc tinh la[t/3]}