TỔNG HỢP MỘT SỐ BÀI TẬP PASCAL
Bài 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.
bài 2
Program Tam_giac;
Begin
Writeln('*********');
Writeln(' *******');
Writeln(' *****');
Writeln('
***');
Writeln('
*');
Readln
End.
Bµi 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.
Bµi 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.
Bµi 5
Program 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.
Bµi 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.
Bµi 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.
Bµi 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.
Bµi 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.
Bµi 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.
Bµi 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 de ket thuc');
Readln
End.
Bµi 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 de ket thuc');
Readln
End.
Bµi 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 de ket thuc');
Readln
End.
Bµi 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 de ket thuc');
Readln
End.
Bµi 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 de ket thuc');
Readln
End.
C¸c vÝ dô
Program PTB2;
Var
a,b,c:Integer;
delta,x1,x2:Real;
Begin
Writeln('GIAI PHUONG TRINH BAC HAI');
Writeln('
--------------');
Repeat
Write('-Nhap he so a= ');
Readln(a);
Until a 0;
Write('-Nhap he so b= ');
Readln(b);
Write('-Nhap he so c= ');
Readln(c);
delta:=b*b-4*a*c;
If delta < 0 Then
Writeln('*Phuong trinh vo nghiem')
Else
If delta = 0 Then
Writeln('*Phuong trinh co 2 nghiem bang nhau X= ',b/2*a:6:2)
Else
Begin
x1:=(-b-sqrt(delta))/2*a;
x2:=(-b+sqrt(delta))/2*a;
Writeln('*Nghiem thu nhat X1= ',x1:6:2);
Writeln('*Nghiem thu hai X2= ',x2:6:2);
End;
readln
End.
Program Ao_thu;
Begin
Writeln('
BAI THO AO THU');
Writeln('Ao thu lanh leo nuoc trong veo');
Writeln('Mot chiec thuyen cau be teo teo');
Writeln('Song biec theo lan hoi gon ty');
Writeln('La vang truoc gio se dua veo');
Writeln('
NGUYEN KHUYEN');
Readln
End.
Program So_hoc;
Var
so1,so2,tong,hieu,tich:Integer;
thuong:Real;
Begin
Write('-Nhap so thu nhat = ');
Readln(so1);
Write('-Nhap so thu hai = ');
Readln(so2);
tong := so1 + so2;
hieu := so1 - so2;
tich := so1 * so2;
thuong := so1 / so2;
Writeln('*Tong cua hai so ',so1,' va ',so2,' =
Writeln('*Hieu cua hai so ',so1,' va ',so2,' =
Writeln('*Tich cua hai so ',so1,' va ',so2,' =
Writeln('*Thuong cua hai so ',so1,' va ',so2,'
Readln
End.
',tong);
',hieu);
',tich);
= ',thuong:6:2);
Program Pithagore;
Var
a,b :Integer;
c:Real;
Begin
Writeln(' CHUONG TRINH TINH CANH HUYEN TAM GIAC VUONG');
Writeln('
theo dinh ly Pithagore');
Write('-Nhap canh a = ');
Readln(a);
Write('-Nhap canh b = ');
Readln(b);
c := Sqrt((a*a) + (b*b));
Writeln('*Canh huyen = ',c:6:2);
Readln
End.
Program Phep_Cong;
Var
so1,so2,so3,tong :Integer;
Begin
Writeln(' CHUONG TRINH THUC HIEN PHEP CONG SO HOC');
Writeln('
co toi da 4 ky so');
Write('-Nhap so thu nhat = ');
Readln(so1);
Write('-Nhap so thu hai = ');
Readln(so2);
Write('-Nhap so thu ba
= ');
Readln(so3);
tong:= so1+so2+so3;
Writeln;
Writeln;
Writeln('-------------------------------');
Writeln;
Writeln('
',so1:4);
Writeln(' + ',so2:4);
Writeln('
Writeln('
Writeln('
Readln
End.
',so3:4);
-----');
= ',tong:5);
Program Lenh_Write;
Begin
Write('Nam ');
Write('Quoc ');
Write('Son ');
Write('Ha ');
Write('Nam ');
Write('De ');
Write('Cu ');
Readln
End.
Program Lenh_Writeln;
Begin
Writeln('Nam ');
Writeln('Quoc ');
Writeln('Son ');
Writeln('Ha ');
Writeln('Nam ');
Writeln('De ');
Writeln('Cu ');
Readln
End.
Program Tam_giac_Pascal;
Begin
Writeln('
1');
Writeln('
1
1');
Writeln('
1
2
1');
Writeln(' 1
3
3
1');
Writeln('1
4
6
4
1');
Readln
End.
Program Hinh_tron;
Var
r:Integer;
s:Real;
Begin
Writeln('CHUONG TRINH TINH DIEN TICH HINH TRON');
Write('-Cho biet ban kinh = ');
Readln(r);
s:=3.1416 * r * r;
Writeln('*Dien tich hinh tron = ',s:6:2,' met vuong');
Readln
End.
Program Khuon_dang;
Var
ky_tu :Char;
chuoi :string[24];
so_nguyen:Integer;
so_thuc:Real;
Begin
Writeln('CHUONG TRINH XUAT DU LIEU THEO KHUON DANG');
Write('-Nhap mot ky tu = ');
Readln(ky_tu);
Write('-Nhap ho ten = ');
Readln(chuoi);
Write('-Nhap mot so nguyen = ');
Readln(so_nguyen);
Write('-Nhap mot so thuc = ');
Readln(so_thuc);
Writeln;
Writeln('------------------------------');
Writeln('XUAT DU LIEU RA MAN HINH');
Writeln(ky_tu);
Writeln(chuoi);
Writeln(so_nguyen);
Writeln(so_thuc);
Readln
End.
... '); Writeln('Ha '); Writeln('Nam '); Writeln('De '); Writeln('Cu '); Readln End Program Tam_giac _Pascal; Begin Writeln(' 1'); Writeln(' 1'); Writeln(' 1'); Writeln(' 3 1'); Writeln('1 1'); Readln