Bài tập Thực hành Pascal lớp 7
BAI 1 TINH DIEN TICH
Program TinhDT;
uses crt;
Var
{tam giac}
canhdaytamgiac: real;
chieucaotamgiac: real;
DT_Tamgiac: real;
{hinh thang}
daylon,daynho,chieucao:real;
DT_Thang:real;
dieukien: char;
BEGIN
clrscr;
DT_Thang:=0; {gan gia tri dau}
Write(' Tinh dien tich hinh thang:');
repeat
writeln('Co tiep tuc khong c/k'); dieukien:=readkey;
if(dieukien ='c') then
begin
write(' Day lon = ');readln(DAYLON);
write(' Day nho = ');readln(dayNho);
write(' Chieu cao= '); readln(chieuCAO);
DT_Thang:=(daylon+daynho)*chieucao/2;
if (daylon <0) or (daynho <0) or (chieucao <0)
then
begin
writeln('---------------------------------------');
writeln('Ban da nhap so khong hop le, cac canh phai >0');
writeln(' Ban co nhap lai khong');
end
else
Writeln(' DIEN TICH HINH THANG = ',DT_Thang:6:3);
end
else break;
BAI 1 TINH DIEN TICH Program TinhDT; uses crt; Var {tam giac} canhdaytamgiac: real; chieucaotamgiac: real; DT_Tamgiac: real; {hinh thang} daylon,daynho,chieucao:real; DT_Thang:real; dieukien: char; BEGIN clrscr; DT_Thang:=0; {gan gia tri dau} Write(' Tinh dien tich hinh thang:'); repeat writeln('Co tiep tuc khong c/k'); dieukien:=readkey; if(dieukien ='c') then begin write(' Day lon = ');readln(DAYLON); write(' Day nho = ');readln(dayNho); write(' Chieu cao= '); readln(chieuCAO); DT_Thang:=(daylon+daynho)*chieucao/2; if (daylon <0) or (daynho <0) or (chieucao <0) then begin writeln('---------------------------------------'); writeln('Ban da nhap so khong hop le, cac canh phai >0'); writeln(' Ban co nhap lai khong'); end else Writeln(' DIEN TICH HINH THANG = ',DT_Thang:6:3); end else break; until (dieukien = 'k'); { Tinh dien tich tamgiac} writeln('******************--------***********'); Writeln(' Tinh dien tich Tam giac'); DT_Tamgiac:=0; repeat writeln('Co tiep tuc khong c/k'); dieukien:=readkey; if(dieukien ='c') then begin write(' Canh day tam giac = ');readln(canhdaytamgiac); write(' Chieu cao tam giac = ');readln(chieucaotamgiac); DT_Tamgiac:=canhdaytamgiac*chieucaotamgiac/2; Writeln(' DIEN TICH TAM GIAC = ',DT_Tamgiac:6:3); end else break; until (dieukien = 'k'); write('Go enter ket thuc chuong trinh---->>'); readln; END. BAI2 : TIM TONG, TRUNG BINH, MAX, MIN { Vi du ve mang mot chieu, phan tu kieu so thuc} { Nhap mot mang mot chieu, n phan tu,hien thi mang da nhap, tinh toan tong cac phan tu va hien thi ket qua, tinh gia tri trung binh va hien thi ket qua} Program Mang; { khai bao ten chuong trinh co the co co the khong can} { Chu y nhung gi viet trong ngoac moc nay thi khi bien dich chuong trinh se bo qua, khong bien dich} uses crt; { khai bao su dung thu vien crt, thu vien crt co rat nhieu ham chuan da duoc dinh nghia trong Pascal, nhu cac ham toan hoc, vao ra man ban phim,...} { Khai bao cac bien su dung} VAR x: array[1..100] of real; n: integer; i: integer; Tong, TrungBinh: real; min,Max: real; BEGIN clrscr; { Xoa man hinh} write(' Nhap so phan tu cua mang N= '); readln(n); for i:=1 to n do begin write('Nhap phan tu tu: ',i,' = '); readln(x[i]); end; { Hien thi mang so thuc da nhap} write(' Go enter de xem mang da nhap:'); readln; clrscr; Write(' MANG DA NHAP NHU SAU: '); writeln; { lenh xuong dong} for i:=1 to n do write('X[',i,']= ',x[i]:6:3,' '); writeln; writeln('Go Enter de xem cac ket qua--->'); readln; clrscr; {tinh tong gia tri va tinh gia tri trung binh cua mang} Tong:=0; TrungBinh:=0; for i:=1 to n do begin Tong:=Tong + x[i]; end; TrungBinh:=Tong/n; writeln('Tong gia tri cua mang ',n, 'phan tu = ',Tong:6:3); writeln(' Gia tri trung binh cua mang do la: ',TrungBinh:6:3); readln; { Tim min} min:=x[1]; for i:=1 to n do if (x[i]<min) then min:=x[i] else min:=min; writeln('Min= ',min:6:3); readln; {Tim max} max:=x[1]; for i:=1 to n do if (x[i]>max) then max:=x[i] else max:=max; writeln('Max= ',max:6:3); write('Go phim Enter de thoat khoi chuong trinh'); readln; END. BAI3: SAP XEP MANG TANG DAN ,GIAM DAN { Chuong trinh nhap 1 day so tu man hinh, kieu phan tu so thuc, In day so da nhap ra man hinh. Sap xep lai day so theo thu tu tang dan, Hien thi day so da sap xep} Program sapxep; uses crt; {Type A= array[1..100] of real;} var X: array[1..100] of real; i,j,n:integer; tg: real; BEGIN clrscr; Write(' Nhap so phan tu( <100) n= '); readln(n); for i:=1 to n do begin write('Nhap phan tu thu: ',i,'= '); readln(X[i]); end; write('Go enter de xem ket qua da nhap-->'); clrscr; {In gia tri da nhap ra man hinh} Writeln(' CAC GIA TRI DA NHAP NHU SAU:'); for i:=1 to n do Write(X[i]:6:3,' '); {Sap xep theo thu tu tang dan} Writeln('Go enter de xem day so da sap xep'); readln;{dung lai de xem} clrscr; { xoa man hinh} tg:=X[1]; for i:=1 to n-1 do for j:=n downto i do if (X[i]>=X[j]) then begin tg:=X[j]; X[j]:=x[i]; X[i]:=tg; end; { IN KET QUA} Writeln(' DAY SO DA SAP XEP THEO THU TU TANG DAN NHU SAU:'); for i:=1 to n do Write(X[i]:6:3,' '); readln; {Sap xep theo thu tu giam dan} Writeln('Go enter de xem day so da sap xep'); readln;{dung lai de xem} clrscr; { xoa man hinh} tg:=X[1]; for i:=1 to n-1 do for j:=n downto i do if (X[i]<=X[j]) then begin tg:=X[j]; X[j]:=x[i]; X[i]:=tg; end; { IN KET QUA} Writeln(' DAY SO DA SAP XEP THEO THU TU GIAM DAN NHU SAU:'); for i:=1 to n do Write(X[i]:6:3,' '); readln; END. BAI 4: TIM SO LON NHAT,SO BE NHAT { Vi du ve mang mot chieu, phan tu kieu so thuc} { Nhap mot mang mot chieu, n phan tu,hien thi ket qua da nhap, tim MIN MAX, tim va in cac so =8.5} Program Mang; { khai bao ten chuong trinh co the co co the khong can} { Chu y nhung gi viet trong ngoac moc nay thi khi bien dich chuong trinh se bo qua, khong bien dich} uses crt; { khai bao su dung thu vien crt, thu vien crt co rat nhieu ham chuan da duoc dinh nghia trong Pascal, nhu cac ham toan hoc, vao ra man ban phim,...} { Khai bao cac bien su dung} VAR x: array[1..100] of real; n: integer; i: integer; min,Max: real; BEGIN clrscr; { Xoa man hinh} write(' Nhap so phan tu cua mang N= '); readln(n); for i:=1 to n do begin write('Nhap phan tu tu: ',i,' = '); readln(x[i]); end; { Hien thi mang so thuc da nhap} write(' Go enter de xem mang da nhap:'); readln; clrscr; Write(' MANG DA NHAP NHU SAU: '); writeln; { lenh xuong dong} for i:=1 to n do write('X[',i,']= ',x[i]:6:3,' '); writeln; writeln('Go Enter de xem cac ket qua---MinMax>'); readln; clrscr; {tim kiem Min Max } min:=x[1];max:=x[1]; for i:=1 to n do begin if (x[i]<min) then min:=x[i] else min:=min; if (x[i]>max) then max:=x[i] else max:=max; end; writeln('Min= ',min:6:3); writeln('Max= ',max:6:3); writeln('Go enter de xem cac so tim duoc'); readln; writeln(' Cac so 8.5 nhu sau:'); for i:=1 to n do if (x[i]=8.5) then write(x[i]:6:3,' '); writeln; write('Go phim Enter de thoat khoi chuong trinh'); readln; END. BAI 5: VE HINH TRON Program ve1; uses crt, graph; var X0,Y0,R: integer; gd,gm: integer; i:integer; Begin clrscr; writeln('Ve duong tron'); writeln('Nhap toa do { 0 < X < 640, 0 < Y0 < 480}:'); write('Nhap X0= ');readln(X0); write('Nhap Y0= ');readln(Y0); write('Nhap ban kinh R= ');readln(R); { Dat che do do hoa} gd:=detect; initgraph(gd,gm,'c:\tp\bgi'); setbkcolor(WHITE); setcolor(RED); setlinestyle(0,0,3); circle(X0,Y0,R); circle(X0,Y0,2);{tam duong tron} setcolor(BLUE); rectangle(50,50,300,250); circle(320,240,R); setfillstyle(0,7);line(X0,Y0,X0+100,Y0+49); setlinestyle(2,0,1); for i:=1 to 10 do begin circle(320,240,i+5); delay(500); end; outtextxy(50,20,'VE DUONG TRON'); readln; closegraph; END.
File đính kèm:
- Bài tập Thực hành Pascal lớp 7.doc