0% found this document useful (0 votes)
74 views11 pages

Phan Thuc Hanh

The document contains 18 Pascal programs that demonstrate solutions to various problems involving strings, arrays, loops, conditionals, and mathematical operations. Specifically: 1. The programs show how to solve linear equations, inequalities, and quadratic equations using conditionals and basic math operations. 2. Programs 3-5 demonstrate calculating employee salaries based on number of days worked and wage rates. 3. Later programs calculate sums, products, factorials, and series up to a given accuracy. 4. String programs manipulate and analyze input strings, counting characters and reversing/capitalizing the text. In summary, the document presents Pascal code for solving a variety of mathematical and text processing problems through programming

Uploaded by

api-19649718
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views11 pages

Phan Thuc Hanh

The document contains 18 Pascal programs that demonstrate solutions to various problems involving strings, arrays, loops, conditionals, and mathematical operations. Specifically: 1. The programs show how to solve linear equations, inequalities, and quadratic equations using conditionals and basic math operations. 2. Programs 3-5 demonstrate calculating employee salaries based on number of days worked and wage rates. 3. Later programs calculate sums, products, factorials, and series up to a given accuracy. 4. String programs manipulate and analyze input strings, counting characters and reversing/capitalizing the text. In summary, the document presents Pascal code for solving a variety of mathematical and text processing problems through programming

Uploaded by

api-19649718
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

®Ò c¬ng phÇn thùc hµnh

C©u 1:gi¶i ph¬ng tr×nh bËc 1 ax =b víi a, b bÊt k×


Program Phuongtrinhbac1;
Uses Crt;
Var a,b: real;
BEGIN
Clrscr;
Write('Cho biet a=');readln(a);
Write('Cho biet b=');readln(b);
If a=0 then if b=0 then Writeln('Vo so nghiem:moi so x bat ky')
Else Writeln('Phuong trinh vo nghiem')
Else Writeln('Phuong trinh co nghiem duy nhat x=',b/a:6:2);
Readln
END.
C©u 2: gi¶i bÊt ph¬ng tr×nh bËc 1 ax >b víi a, b bÊt k×
Program b©tphuongtrinhbac1;
Uses Crt;
Var a,b: real;
BEGIN
Clrscr;
Write('nhap a=');readln(a); Write('nhap b=');readln(b);
If a=0 then
if b<0 then Writeln('phuong trinh co vo so nghiem,moi so x bat ki')
Else Writeln('phuong trinh vo nghiem')
Else if a>0 then writeln('nghiem la x>',b/a:7:2)
Else writeln('nghiem la x<',b/a:7:2);
Readln
END.
C©u 3 : gi¶i ph¬ng tr×nh bËc 2 ax2 +bx +c =0 víi a,b,c bÊt k× , a#0
C1: if……..then…..else
Program Phuongtrinhbac2;
Uses Crt;
Var a,b,c,d,x1,x2:real;
BEGIN Clrscr;
Write('Nhap a,b,c');readln(a,b,c);
D:=b*b-4*a*c;
If D<0 then Writeln('Phuong trinh vo nghiem')
Else if D=0 then Writeln('nghiem kep x=',b/(2*a):6:2)
Else
Begin
X1:=(-b-sqrt(D))/(2*a);
X2:=(-b+sqrt(D))/(2*a);
Writeln('2 nghiem x1=',x1:6:2,'x2=',x2:6:2);
End;
Readln
END.
C2: if……then
Program Phuongtrinhbac2;
Uses Crt;
Var a,b,c,d,x1,x2:real;
BEGIN Clrscr;
Write('Nhap a,b,c');readln(a,b,c);
D:=b*b-4*a*c;
If D<0 then Writeln('Phuong trinh vo nghiem');
if D=0 then Writeln('nghiem kep x=',b/(2*a):6:2);
if D>0 then
begin
X1:=(-b-sqrt(D))/(2*a);
X2:=(-b+sqrt(D))/(2*a);
Writeln('2 nghiem x1=',x1:6:2,'x2=',x2:6:2);
end;
Readln
END.
C©u 5:nhËp tªn , l¬ng , sè ngµy c«ng cña 1 c«ng nh©n trong th¸ng 11/2008 .TÝnh tiÒn thëng theo nguyªn
t¾c : nÕu sè ngµy c«ng díi 15 th× thëng =0 , tõ 15 ®Õn 26 th× thëng =20% l¬ng , trªn 26 thëng =30% l¬ng
. In kÕt qu¶ ra (víi th«ng b¸o tªn g× , sè ngµy c«ng bao nhiªu , thëng bao nhiªu)

program thuong;
uses crt;
var th,lg:real;ten:string[30];loai:byte;
BEGIN
clrscr;
write('nhap ten cong nhan:');readln(ten);
write('nhap loai cong nhan do (1/2/3 ) : ');readln(loai);
write('nhap luong cong nhan do:');readln(lg);
case loai of
1:th:=lg*30/100;
2:th:=lg*20/100;
else th:=0;
end;
writeln('cong nhan',ten,'duoc thuong',th:8:0,'dong');
readln
end.

C©u 6 : cho biÕt «ng A cã sè tiÒn vèn V , muèn göi tiÕt kiÖm kh«ng k× h¹n (l·i suÊt 0,16% mçi th¸ng ) .
§Ó nhËn ®îc sè tiÒn >= S , «ng ph¶I göi bao nhiªu th¸ng vµ tiÒn nhËn ®îc chÝnh x¸c la bao nhiªu
program tietkiem;
uses crt;
var i:integer;
v,t:real;
BEGIN clrscr;
write('nhap von,tien ');readln(v,t);
if V<T then
Repeat
i:=i+1;
v:=v+v*16/1000
until v>=t;
writeln('can gui ',i:2,'thang duoc nhan',v:8:1,'dong');
readln
END.
C©u 7:nhap 1 day so nguyªn , muon dung go so 0 . tinh tong va gia tri trung binh
C1: dung while……..do
Program Trungbinh;
Uses Crt;
Var n,s,a:integer;
BEGIN
Clrscr;a:=1;
While a<>0 do
begin
write('Nhap so nguyen a:');readln(a);
if a>0 then begin n:=n+1;s:=s+a;end;
end;
write('co',n:2,'s.duong,Tong cac s.duong s=',s:4,'Tr.binh cong=',s/n:6:2);
readln
END.
C2; dung repeat…..until
Program Trungbinh;
Uses crt;
Var n,s,a:integer;
BEGIN
Clrscr;
Repeat
write('Nhap so nguyen a:');readln(a);
if a>0 then begin n:=n+1;s:=s+a;end;
until a=0;
write('co',n:2,'s.duong,Tong cac s.duong s=',s:4,'tr.binh cong=',s/n:6:2);
readln
END.
C©u 8:xac dinh uscln cua 2 so m, n
C1; while…..do
Program USCLN;
Uses Crt;
Var m,n:integer;
BEGIN
Clrscr;
Write('Nhap m=');readln(m);Write('Nhap n=');readln(n);
Write('USCLN cua',m:3,'va',n:3,'la:');
While m<>n do
If m>n then m:=m-n else n:=n-m;
Writeln(m);
Readln
END.
C2; repeat……until
Program Uocso;
Uses Crt;
Var m,n:integer;
BEGIN
Clrscr;
Write('Nhap m=');readln(m);Write('Nhap n=');readln(n);
Write('USCLN cua',m:3,'va',n:3 , 'la:');
if m<>n then
Repeat
if m>n then m:=m-n else n:=n-m;
until m=n;
write(m);
Readln
END.
C©u 9:tinh gia tri lon nhat , nho nhat cua 3 so m,n,p
program gtmax;
uses crt;
var m,n,p,max,min:integer;
BEGIN
clrscr;write('chom,n,p=');readln(m,n,p);
if m>n then begin max:=m; min:=n; end
else begin max:=n; min:=m; end;
if p>max then max:=p; if p<min then min:=p;
write('max(',m:2,',',n:2,',',p:2,')=',max:4);
write('min(',m:2,',',n:2,',',p:2,')=',min:4);
readln
end.

C©u 10: nhap ten chu xe , gia tri xe , xe(m) hay xe cu(c) . tinh thue xe theo nguyen tac neu xe tren 25 trieu
thi thue xe la 7% gia tri xe , tu 10 trieu den 25 trieu thue la 5% gia tri xe , duoi 10 trieu thue la 1 trieu dong
. neu la xe cu giam 50% thue
program thuexe;
uses crt;
var ten:string;gt,th:real;l:char;
BEGIN clrscr;
write('ten,gia tri xe,loai:');readln(ten,gt,l);
if gt>25 then th:=gt*7/100 else if gt>10 then th:=gt*5/100 else gt:=1;
if upcase (l)='C' then th:=th/2;
writeln('ong ',ten,' phai nop ',th:8:1,' trieu dong ');
readln
end.

C©u 11: tinh tong s=1+2+…+n ; va tich t=1*2*…*n


tÝch
Program Tich;
Uses crt;
Var n,i:integer;T:Longint;
BEGIN
Clrscr;Write('Nhap n=');readln(n);T:=1;
for i:=1 to n do T:=T*i;
Write('Tich T=1*2*...*',n:2,'=',n:2,'!=',T:8);
readln
END.
Tong
C1;
Program Tong;
Uses crt;
Var n,i,s:integer;
BEGIN
Clrscr;write('Nhap n=');readln(n);
for i:=1 to n do s:=s+i;
write('Tong s=1+2+...+',n:2,'=',s:5);
readln
END.
C2; while…..do
Program Tong;
Uses crt;
Var n,s,i:integer;tl:char;
BEGIN
Clrscr;Tl:='c';
while upcase(tl)='c' do
begin
s:=0;
write('Nhap n=');readln(n);
for i:=1 to n do s:=s+i;
writeln('Tong s=1+2+...+',n:2,'=',s:4);
write('Tiep tuc khong?:');readln(tl);
end;
write('Go phim Enter,Good bye!');
readln
END.
C©u 12 : tinh tong giai thua 1 ! +2 ! +…+n !
C1:
Program tong;
uses crt;
var n,s,i,j,t:integer;
BEGIN
clrscr;write('nhap n=');readln(n);
for i:=1 to n do
begin
t:=1;
for j:=1 to i do T:=T*j;
writeln(i:2,'!=',T:3);
S:=s+t;
end;
write('S=1!+2!+...+',n:2,'!=',s:4);
readln
END.
Program tong;
uses crt;
var n,s,i,j,m,a,t:integer;tl:char;
BEGIN
clrscr;write('nhap n=');readln(n);
for i:=1 to n do
begin
t:=1;
for j:=1 to i do T:=T*j;
writeln(i:2,'!=',T:3);
S:=s+t;
end;
write('S=1!+2!+...+',n:2,'!=',s:4);
readln
END.
C2:
program tinhgiaithua;
uses crt;
var i,n:integer;T,S:longint;
BEGIN
clrscr; T:=1;
write('nhap n= ');readln(n);
for i:=1 to n do
begin
T:=T*i;
S:=S+T;
end;
write('1!+2!+...+',n:2,'!=',S);
readln
END.
C©u 13: tinh tong 1 +1/2 +…+1/n
program tong;
uses crt;
var n,i:integer;s:real;
BEGIN clrscr;
write('nhap n= ');readln(n);
for i:=1 to n do s:=s+1/i;
write(' tong s=1+1/2+...+1/',n:2,'=',s:5:1);
readln
end.

C©u 14 :tinh tong 1 ! +1/2 !+…_1/n !


Program Tonggiaithua;
Uses Crt;
Var i,n:integer;s,sh:real;
BEGIN
Clrscr;
Write('Nhap n=');readln(n);sh:=1;
for i:=1 to n do begin sh:=sh*1/i;s:=s+sh;writeln(sh:5:3);end;
write('Tong 1/1!+1/2!+...+1/',n:2,'!=',s:5:3);
Readln
END.
C©u 15: tinh tong 1+1/2+…+1/n … voi do chinh xac la 1/n<0.0001
program tong;
uses crt;
var i:integer;s:real;
BEGIN clrscr;
i:=1;while 1/i > 0.01 do
begin
s:=s+1/i;i:=i+1;
end;
write(' tong s=1+1/2+...+1/',i:2,'=',s:5:1);
readln
end.
C©u 16 : nhap xau va in xau da cho
a)theo thu tu nguoc lai
b)voi toan bo la chu in
program xau;
uses crt;
var n,i:integer; x:string[30];
begin
clrscr; write('cho xau =');readln(x);
n:=length(x);
for i:=n downto 1 do write(x[i]); writeln;
for i:=1 to n do
begin
x[i]:=upcase(x[i]);
write(x[i]);
end;
writeln;
readln;
end.
C©u 17: nhap xau va tinh xem trong xau chu cai a xuat hien bao nhieu lan, khong phan biet chu in , chu
thuong
program xau;
uses crt;
var m,n,i:integer; x:string[30];
begin
clrscr; write('cho xau ='); readln(x);
n:=length(x);m:=0;
for i:=1 to n do
if upcase(x[i])='A' then m:=m+1;
writeln('so chu a trong xau ',m);
readln;
end.

C©u 18 : nhap xau va tinh xem trong xau cac chu cai ( khong phan biet chu in , chu thuong ) xuat hien bao
nhieu lan .
C1:
program XAU;
uses crt;
var X:STRING; I,N,M,L:INTEGER;ch:char;
BEGIN
clrscr;write('Nhap xau:');readln(x);
n:=length(x);
for i:=1 to n do if upcase(x[i])='A' then m:=m+1;
writeln('So chu cai A trong xau: ',m);
for ch:='A' to 'Z' do
begin
l:=0;
for i:=1 to n do
begin

x[i]:=upcase(x[i]);
if x[i]=ch then l:=l+1;
end;
if l>0 then writeln('So chu cai ',ch:2,' trong xau: ',l);
end;

readln
END.
C2:
program xau;
uses crt;
var x:string; i,n,m,l:integer;ch:char;
BEGIN
clrscr;
write('Nhap xau:');readln(x);n:=length(x);
for ch:='A' to 'Z' do
begin
l:=0;
for i:=1 to n do if upcase(x[i])=ch then l:=l+1;
if l>0 then writeln('chu cai',ch,' xuat hien',l:2);
end;
readln
END.
C©u 22: giai bai toan co : vua ga vua cho bo lai cho tron , 36 con , 100 chan chan . tinh so ga , so cho
program gacho;
uses crt;
var ga,cho:integer;
BEGIN
clrscr;
for ga:=0 to 50 do
for cho:=0 to 25 do
if(ga+cho=36) and (2*ga+4*cho=100)then
write('so ga:',ga:3,'so cho:',cho);
readln
END.

C©u 23 :lap thu tuc nhap 1 so nguyen n ham gt ( de tinh n ! ) . ap dung tinh to hop chap k cua n phan tu
Ckn =-------------n ! k ! (n – k) !-----------------

C1:
PROGRAM giaithua;
uses crt;
var i,s,n,k:integer;
Procedure nhap (var n:integer);
var traloi:char;
begin
repeat
readln(n);
write('sua khong?:');readln(traloi);
until upcase(traloi)='K';
end;
Function gt(n:integer):longint;
var I:integer;T:longint;
begin
T:=1;for I:=1 to n do T:=T*i;gt:=t;
end;
BEGIN
CLRSCR;
write('nhap so n:');nhap(n);
for I:=1 to n do s:=s+i;
writeln('1+2+...+',n:3,'=',s');
writeln(n:2,'!=',gt(n));
writeln('nhap so k:'); nhap(k);
writeln('to hop chap',k:2,'cua',n:3,'phan tu la:',gt(n)/(gt(k)*gt(n-k)):8:0);
readln
end.
C2: Program Tohop;
uses crt;
var n,k:integer;C:real;
Function gt(m:integer):longint;
var I:integer;T:longint;
begin
T:=1;
for i:=1 to m do T:=T*i;
gt:=T;
End;
BEGIN
Clrscr; write ( ‘ k,n = ‘ ) ; readln (k,n);
C:= gt(n)/(gt(k)*gt(n-k));
writeln('to hop chap',k:3,'cua',n:3,'phan tu la ',C:6:0);
Readln
END.

C©u 24 : lap thu tuc nhap (m,n) (de nhap 2 so m,n ) ; lap ham uscln (m,n) ( de tinh uscln cua m va n ) , ap
dung tinh bscnn cua m,n biat rang bscnn (m,n) = m*n/uscln(m,n)
program uocso;
uses crt;
var i,s,n,m,k:integer;
procedure nhap(var m,n:integer);
var traloi:char;
begin
repeat
readln(m,n);
write('sua khong?:');readln(traloi);
until upcase(traloi)='K';
end;
function USCLN(m,n:integer):integer;
begin
while m<>n do
if m>n then m:=m-n else n:=n-m;
USCLN:=m;
end;
BEGIN
CLRSCR;
write('nhap 2 so m,n:');nhap(m,n);
writeln('USCLN cua',m:3,'va',n:3,'la:',USCLN(m,n));
writeln('BSCNN cua',m:3,'va',n:3,'la:',m*n/USCLN(m,n):6:0);
readln;
END.
C©u 25: hay xac dinh ngay x cua thang 11/2008 roi vao thu may , biat rang ngay 1/11/2008 la thu 7
program thu;
uses crt;
var ng:integer;
BEGIN
clrscr;
write('nhap ngay:');readln(ng);
write('ngay',ng:3,'thang 11/2008 la thu ');
case (ng mod 7)of
0: write('sau');
1: write('bay');
2: write('chu nhat');
3: write('hai');
4: write('ba');
5: write('tu');
6: write('nam');
end;
readln;
END.

C©u 26 : nhap mat khau vao may , neu dung (kt13t2) thi may hien len cau “hello , chao ban “ , nguoc lai
mat khau sai , may hien len “ban la nguoi la , good bye “ , cai tien chuong trinh de cho phep sua 3 lan
program matkhau;
uses crt;
var n,i,j:integer;y:real;mk:string[6];
BEGIN clrscr;
gotoxy(12,8);textbackground(6);textcolor(14);mk:=' ';
while (mk<>'kt14t7') and (i<3) do
begin
i:=i+1;gotoxy(12,8+i);textbackground(6);
write('cho biet mat khau:');readln(mk);n:=length(mk);
for j:=1 to n do mk[j]:=upcase(mk[j]);
end;
gotoxy(18,18);textbackground(6);textcolor(0);
if mk='kt14t7' then write('hello,chao ban!')
else write('ban la nguoi la,good bye!');
readln
END.
C©u 28 : tim so co 3 chu so sao cho so do = tong lap Phuong cac chu so
program so;
uses crt;
var a,i,j ,k:integer;tl:char;
BEGIN
Clrscr; tl:='C';
for i:=1 to 9 do
for j:=0 to 9 do
for k:=0 to 9 do
if 100*i+10*j+k=i*i*i+j*j*j+k*k*k then write(100*i+10*j+k:6);
readln
END.

You might also like