Tải bản đầy đủ (.pdf) (29 trang)

giải bài tập sách giáo khoa tin học 11

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (254.44 KB, 29 trang )

Great by: Nguyễn Trọng Hoàng Email:





Gi¶i Bµi
Gi¶i Bµi Gi¶i Bµi
Gi¶i Bµi
TËp Tin
TËp Tin TËp Tin
TËp Tin
Häc 11
Häc 11Häc 11
Häc 11








































Great by: Nguyn Trng Hong Email:


Chơng 1
Chơng 1Chơng 1
Chơng 1
:

: :
:


ột số khái niệm về lập trình và ngôn ngữ lập trình
ột số khái niệm về lập trình và ngôn ngữ lập trìnhột số khái niệm về lập trình và ngôn ngữ lập trình
ột số khái niệm về lập trình và ngôn ngữ lập trình








Bài tập
Bài tậpBài tập
Bài tập


1. Ngi ta phi xõy dng ngụn ng lp trỡnh bc cao vỡ
- Ngụn ng lp trỡnh bc cao gn gi vi t nhiờn hn, thun tin cho
ủụng ủo ngi lp trỡnh.
- Ngụn ng lp trỡnh bc cao núi chung khụng ph thuc vo loi mỏy,
cựng mt chng trỡnh cú th thc hin nhiu mỏy khỏc nhau.
- Chng trỡnh vit bng ngụn ng bc cao d hiu, d hiu chnh v d
nõng cp hn.
- Ngụn ng lp trỡnh bc cao cho phộp lm vic vi nhiu kiu d liu v
cỏch t chc d liu ủa dng, thun tin cho mụ t thut toỏn.
2. Chng trỡnh dch l chng trỡnh ủc bit, cú chc nng chuyn ủi

chng trỡnh ủc vit trờn ngụn ng lp trỡnh bc cao thnh chng
trỡnh thc hin ủc trờn mỏy tớnh.
3.
- Biờn dch: duyt, kim tra, phỏt hin li, xỏc ủnh chng trỡnh ngun
cú dch ủc khụng. Dch ton b chng trỡnh ngun thnh mt
chng trỡnh ủớch cú th thc hin trờn mỏy v cú th lu tr li ủ s
dng v sau khi cn.
- Thụng dch: ln lt dch tng cõu lnh ra ngụn ng mỏy ri thc hiờn
ngay cõu lnh va dch ủc hoc thụng bỏo li nu khụng dch ủc.
4. Cỏc ủim khỏc nhau gia tờn dnh riờng v tờn chun: tờn dnh riờng
khụng ủc dựng khỏc vi ý ngha xỏc ủnh, tờn chun cú th dựng vi
ý ngha khỏc.
5. ỳng: tamgiac, bai5a, xemxonxiu_ngu
6. C: 6,23

6.23
E: A20 tờn cha cú giỏ tr
G:
64
+
H: C

CI: TRUE true l hng logic.











M
MM
M
Great by: Nguyễn Trọng Hoàng Email:



Ch−¬ng 2
Ch−¬ng 2Ch−¬ng 2
Ch−¬ng 2
:
: :
:





h−¬ng tr×nh ®¬n gi¶n
h−¬ng tr×nh ®¬n gi¶nh−¬ng tr×nh ®¬n gi¶n
h−¬ng tr×nh ®¬n gi¶n








Bµi Thùc Hµnh Sè 1
Bµi Thùc Hµnh Sè 1Bµi Thùc Hµnh Sè 1
Bµi Thùc Hµnh Sè 1






*****
**********
*****







1.
Sự khác nhau giữa hằng có ñặt tên và tên biến: Giá trị của hằng có ñặt
tên không thay ñổi khi thực hiện chương trình còn giá trị của biến có
thể thay ñổi tại từng thời ñiểm thực hiện chương trình.
2.
Khai báo biến nhằm những mục ñích sau:
- Xác ñịnh kiểu của biến. Trình dịch sẽ biết cách tổ chức ô nhớ chứa giá
trị của biến.
- ðưa tên biến vào danh sách các ñối tượng ñược chương trình quản lí.
- Trình dịch biết cách truy cập giá trị của biến và áp dụng thao tác thích

hợp cho biến.
3.
integer, real, extended, longint.
4.
D
5.
C
6.
))***1/(1/()/(*)1( xxxxazyxz
+

+
+

7.
a)
b
a2
; b)
2
abc
; c)
ac
b
; d)
ba
b
+
2


8.
a)
program bai8a;
program bai8a;program bai8a;
program bai8a;


uses cr
uses cruses cr
uses crt;
t;t;
t;


var x,y:real;
var x,y:real;var x,y:real;
var x,y:real;




kt:boolean;
kt:boolean;kt:boolean;
kt:boolean;


begin
beginbegin
begin



clrscr;
clrscr;clrscr;
clrscr;


write('Nhap x: ');readln(x);
write('Nhap x: ');readln(x);write('Nhap x: ');readln(x);
write('Nhap x: ');readln(x);


write('Nhap y: ');readln(y);
write('Nhap y: ');readln(y); write('Nhap y: ');readln(y);
write('Nhap y: ');readln(y);


kt:=false;
kt:=false;kt:=false;
kt:=false;


if ((y<1) or (y=1)) and ((y>abs(x)) or (y=abs(x)))
if ((y<1) or (y=1)) and ((y>abs(x)) or (y=abs(x))) if ((y<1) or (y=1)) and ((y>abs(x)) or (y=abs(x)))
if ((y<1) or (y=1)) and ((y>abs(x)) or (y=abs(x)))
then
thenthen
then


kt:=true;

kt:=true;kt:=true;
kt:=true;


if kt then write('Diem vua nhap thuoc phan gach
if kt then write('Diem vua nhap thuoc phan gach if kt then write('Diem vua nhap thuoc phan gach
if kt then write('Diem vua nhap thuoc phan gach
cheo')
cheo')cheo')
cheo')





C
CC
C



Great by: Nguyễn Trọng Hoàng Email:


else write('Khong thu
else write('Khong thuelse write('Khong thu
else write('Khong thuoc');
oc');oc');
oc');



readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





b)


program bai8;
program bai8;program bai8;
program bai8;


uses crt;

uses crt;uses crt;
uses crt;


var x,y:real;
var x,y:real;var x,y:real;
var x,y:real;




kt:boolean;
kt:boolean;kt:boolean;
kt:boolean;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap x: ');readln(x);
write('Nhap x: ');readln(x);write('Nhap x: ');readln(x);
write('Nhap x: ');readln(x);



write('Nhap y: ');readln(y);
write('Nhap y: ');readln(y); write('Nhap y: ');readln(y);
write('Nhap y: ');readln(y);


kt:=false;
kt:=false;kt:=false;
kt:=false;


if (abs(y)<=1) and (abs(x)<=1) then
if (abs(y)<=1) and (abs(x)<=1) thenif (abs(y)<=1) and (abs(x)<=1) then
if (abs(y)<=1) and (abs(x)<=1) then


kt:=true;
kt:=true;kt:=true;
kt:=true;


if kt then write('Diem vua nhap thuoc phan ga
if kt then write('Diem vua nhap thuoc phan gaif kt then write('Diem vua nhap thuoc phan ga
if kt then write('Diem vua nhap thuoc phan gach
ch ch
ch
cheo')
cheo')cheo')
cheo')



else write('Khong thuoc');
else write('Khong thuoc');else write('Khong thuoc');
else write('Khong thuoc');


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô








Bài 9.



rogram bai9;
rogram bai9;rogram bai9;
rogram bai9;


uses crt;
uses crt;uses crt;
uses crt;


const pi= 3.1416;
const pi= 3.1416;const pi= 3.1416;
const pi= 3.1416;


var a,s:real;
var a,s:real;var a,s:real;
var a,s:real;


begin
begin begin
begin


clrscr;
clrscr;clrscr;
clrscr;



repeat
repeatrepeat
repeat


write('Nhap ban kinh duong tron: ');
write('Nhap ban kinh duong tron: ');write('Nhap ban kinh duong tron: ');
write('Nhap ban kinh duong tron: ');


readln(a);
readln(a);readln(a);
readln(a);


if a<0 then writeln('Nhap lai!');
if a<0 then writeln('Nhap lai!');if a<0 then writeln('Nhap lai!');
if a<0 then writeln('Nhap lai!');


until a>0;
until a>0;until a>0;
until a>0;


s:=(a*a*pi)/2;
s:=(a*a*pi)/2;s:=(a*a*pi)/2;
s:=(a*a*pi)/2;



wri
wriwri
write('Dien
te('Diente('Dien
te('Dien

tichphan gach cheo: ',s:8:3);
tichphan gach cheo: ',s:8:3);tichphan gach cheo: ',s:8:3);
tichphan gach cheo: ',s:8:3);


Great by: Nguyễn Trọng Hoàng Email:


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô

VÝ Dô








Bài 10.
program bai10;
program bai10;program bai10;
program bai10;


uses crt;
uses crt;uses crt;
uses crt;


const g= 9.8;
const g= 9.8;const g= 9.8;
const g= 9.8;


var v, h:real;
var v, h:real;var v, h:real;
var v, h:real;



begin
begin begin
begin


clrscr;
clrscr;clrscr;
clrscr;


repeat
repeatrepeat
repeat


write('Nhap do cao: ');
write('Nhap do cao: ');write('Nhap do cao: ');
write('Nhap do cao: ');


readln(h);
readln(h);readln(h);
readln(h);


if h<0 then writeln('Nhap lai!');
if h<0 then writeln('Nhap lai!');if h<0 then writeln('Nhap lai!');
if h<0 then writeln('Nhap lai!');



until h>0;
until h>0;until h>0;
until h>0;


v:=sqrt(2*g*h);
v:=sqrt(2*g*h);v:=sqrt(2*g*h);
v:=sqrt(2*g*h);


write('Van toc
write('Van tocwrite('Van toc
write('Van toc: ',v:8:3);
: ',v:8:3);: ',v:8:3);
: ',v:8:3);


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô

VÝ DôVÝ Dô
VÝ Dô













































Great by: Nguyn Trng Hong Email:





Chơng 3
Chơng 3Chơng 3
Chơng 3
:
: :
:






ấu trúc rẽ nhánh và lặp
ấu trúc rẽ nhánh và lặpấu trúc rẽ nhánh và lặp
ấu trúc rẽ nhánh và lặp













Bài Thực Hành Số 2
Bài Thực Hành Số 2Bài Thực Hành Số 2
Bài Thực Hành Số 2






*****
**********

*****







1. SGK
2. Cõu lnh ghộp l mt cõu lnh ủc hp thnh t nhiu cõu lnh thnh
phn. Cõu lnh ghộp nhm thc hin thao tỏc gm nhiu thao tỏc thnh
phn. Mi thao tỏc thnh phn ng vi mt cõu lnh ủn hoc mt cõu lnh
ghộp khỏc. Cõu lnh ghộp l mt trong cỏc yu t ủ to kh nng chng
trỡnh cú cu trỳc. Cỏc cõu lnh ủt gia begin v end;
Bi 3.
Program tong1a;
Program tong1a;Program tong1a;
Program tong1a;


Uses crt;
Uses crt;Uses crt;
Uses crt;


Var S: real;
Var S: real;Var S: real;
Var S: real;



a, N: integer;
a, N: integer; a, N: integer;
a, N: integer;


begin
beginbegin
begin


clrscr;
clrscr; clrscr;
clrscr;


write('Nhap a: ');readln(a);
write('Nhap a: ');readln(a); write('Nhap a: ');readln(a);
write('Nhap a: ');readln(a);


S:=1.0/a;
S:=1.0/a; S:=1.0/a;
S:=1.0/a;




N:=1;
N:=1;N:=1;
N:=1;



While n<=100 do
While n<=100 do While n<=100 do
While n<=100 do




Begin
BeginBegin
Begin






S:=S+1.0/(a+N);
S:=S+1.0/(a+N);S:=S+1.0/(a+N);
S:=S+1.0/(a+N);






N:=N+1
N:=N+1N:=N+1
N:=N+1;

;;
;




End
EndEnd
End;
;;
;


Writeln('Tong S la: ',S:8:4);
Writeln('Tong S la: ',S:8:4); Writeln('Tong S la: ',S:8:4);
Writeln('Tong S la: ',S:8:4);


Readln
Readln Readln
Readln


End
EndEnd
End.

.



Ví Dụ
Ví DụVí Dụ
Ví Dụ














C
CC
C



Great by: Nguyễn Trọng Hoàng Email:





Bài 4.


.


a)
a)a)
a)


program
program program
program bai4a;
bai4a;bai4a;
bai4a;


uses crt;
uses crt;uses crt;
uses crt;


var x, y, z:real;
var x, y, z:real;var x, y, z:real;
var x, y, z:real;


begin
beginbegin
begin



clrscr;
clrscr; clrscr;
clrscr;


write('nhap hai so x va y: '); readln(x,y);
write('nhap hai so x va y: '); readln(x,y);write('nhap hai so x va y: '); readln(x,y);
write('nhap hai so x va y: '); readln(x,y);


if x*x+y*y<=1 then
if x*x+y*y<=1 then if x*x+y*y<=1 then
if x*x+y*y<=1 then


begin
begin begin
begin


z:=(x*x+y*y);
z:=(x*x+y*y); z:=(x*x+y*y);
z:=(x*x+y*y);


writeln('tong can tim: ',z:9);
writeln('tong can tim: ',z:9); writeln('tong can tim: ',z:9);
writeln('tong can tim: ',z:9);





end
endend
end;
;;
;


if (x*x+y*y>1) and (y>=x) then
if (x*x+y*y>1) and (y>=x) then if (x*x+y*y>1) and (y>=x) then
if (x*x+y*y>1) and (y>=x) then




begin
beginbegin
begin


z:=(x+y);
z:=(x+y); z:=(x+y);
z:=(x+y);


writeln('tong can tim: ',z:9);
writeln('tong can tim: ',z:9); writeln('tong can tim: ',z:9);
writeln('tong can tim: ',z:9);





end
endend
end;
;;
;


if (x*x+y*y>1) and (y<x) then
if (x*x+y*y>1) and (y<x) then if (x*x+y*y>1) and (y<x) then
if (x*x+y*y>1) and (y<x) then


begin
begin begin
begin


z:=0.5;
z:=0.5; z:=0.5;
z:=0.5;


writeln('tong can tim: ',z);
writeln('tong can tim: ',z); writeln('tong can tim: ',z);
writeln('tong can tim: ',z);





end
endend
end;
;;
;


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô






b)
b)b)
b)


program bai4
program bai4program bai4
program bai4b
bb
b;
;;
;


uses crt;
uses crt;uses crt;
uses crt;


var x,y,z,a,b,r:real;
var x,y,z,a,b,r:real;var x,y,z,a,b,r:real;
var x,y,z,a,b,r:real;


begin
beginbegin
begin


clrscr;

clrscr;clrscr;
clrscr;




write('Nhap x: ');readln(x);
write('Nhap x: ');readln(x);write('Nhap x: ');readln(x);
write('Nhap x: ');readln(x);


write('Nhap y: ');readln(y);
write('Nhap y: ');readln(y); write('Nhap y: ');readln(y);
write('Nhap y: ');readln(y);


write('Nhap toa do tam hinh tron: ');
write('Nhap toa do tam hinh tron: '); write('Nhap toa do tam hinh tron: ');
write('Nhap toa do tam hinh tron: ');


readln(a,b);
readln(a,b); readln(a,b);
readln(a,b);


write('Nhap ban kinh r: ');readln(r);
write('Nhap ban kinh r: ');readln(r); write('Nhap ban kinh r: ');readln(r);
write('Nhap ban kinh r: ');readln(r);



if sqrt(sqr(x
if sqrt(sqr(x if sqrt(sqr(x
if sqrt(sqr(x-

-a)+sqr(x
a)+sqr(xa)+sqr(x
a)+sqr(x-

-b))<r then
b))<r thenb))<r then
b))<r then


begin
begin begin
begin


Great by: Nguyễn Trọng Hoàng Email:


z:=abs(x)+abs(y);
z:=abs(x)+abs(y);z:=abs(x)+abs(y);
z:=abs(x)+abs(y);


writeln('Z= ',z:3:3);
writeln('Z= ',z:3:3); writeln('Z= ',z:3:3);
writeln('Z= ',z:3:3);





end
endend
end


else
elseelse
else


b
b b
begin
egin egin
egin


z:=x+y;
z:=x+y; z:=x+y;
z:=x+y;


writeln('Z= ',z:3:3);
writeln('Z= ',z:3:3); writeln('Z= ',z:3:3);
writeln('Z= ',z:3:3);





end
endend
end;
;;
;


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô






Bài 5.
a)
a)a)
a)


Program
Program Program
Program bai
baibai
bai5a;
5a;5a;
5a;


Uses crt;
Uses crt;Uses crt;
Uses crt;


Const n=50;
Const n=50;Const n=50;
Const n=50;


Var i: integer;
Var i: integer;Var i: integer;
Var i: integer;





Y:real;
Y:real; Y:real;
Y:real;


Begin
BeginBegin
Begin




Clrscr;
Clrscr;Clrscr;
Clrscr;




for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do




Y:=i/(i+1);
Y:=i/(i+1);Y:=i/(i+1);

Y:=i/(i+1);




Write('Tong Y: ',y
Write('Tong Y: ',yWrite('Tong Y: ',y
Write('Tong Y: ',y:9:3
:9:3:9:3
:9:3);
););
);




Readln
ReadlnReadln
Readln


End
EndEnd
End.

.


VÝ Dô
VÝ DôVÝ Dô

VÝ Dô








b)
b)b)
b)


progr
progrprogr
program
am am
am bai
baibai
bai5b;
5b;5b;
5b;


uses crt;
uses crt;uses crt;
uses crt;



var
var var
var

n:longint;
n:longint;n:longint;
n:longint;




e,sh:real;
e,sh:real;e,sh:real;
e,sh:real;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


sh:=1/2;
sh:=1/2; sh:=1/2;
sh:=1/2;



n:=2;
n:=2; n:=2;
n:=2;


Great by: Nguyễn Trọng Hoàng Email:


e:=2+sh;
e:=2+sh; e:=2+sh;
e:=2+sh;


while sh>=2*1e
while sh>=2*1e while sh>=2*1e
while sh>=2*1e-

-16 do
16 do16 do
16 do








begin

beginbegin
begin










n:=n+1;
n:=n+1;n:=n+1;
n:=n+1;










sh:=sh*(1/n);
sh:=sh*(1/n);sh:=sh*(1/n);
sh:=sh*(1/n);











e:=e+sh;
e:=e+sh;e:=e+sh;
e:=e+sh;








end
endend
end;
;;
;







writeln('Gia tri e(n) la: ',e:10:6);
writeln('Gia tri e(n) la: ',e:10:6); writeln('Gia tri e(n) la: ',e:10:6);
writeln('Gia tri e(n) la: ',e:10:6);


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





Bài
Bài Bài
Bài 6.
6.6.
6.



progra
prograprogra
program
m m
m Bai6
Bai6Bai6
Bai6;
;;
;


uses crt;
uses crt;uses crt;
uses crt;


var x, y:byte;
var x, y:byte;var x, y:byte;
var x, y:byte;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;

clrscr;


for x:=1 to 36 do
for x:=1 to 36 dofor x:=1 to 36 do
for x:=1 to 36 do


for y:=0 to 20 do
for y:=0 to 20 dofor y:=0 to 20 do
for y:=0 to 20 do


if (x+y=36) and (2*x+4*y=100) then
if (x+y=36) and (2*x+4*y=100) thenif (x+y=36) and (2*x+4*y=100) then
if (x+y=36) and (2*x+4*y=100) then


begin
beginbegin
begin


writeln('Co ',x,' con Ga');
writeln('Co ',x,' con Ga');writeln('Co ',x,' con Ga');
writeln('Co ',x,' con Ga');


write('Co ',y,' con Cho');
write('Co ',y,' con Cho');write('Co ',y,' con Cho');

write('Co ',y,' con Cho');


end
endend
end;
;;
;


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô






Bài 7.
program
program program
program Bai7
Bai7Bai7
Bai7;
;;
;


uses crt;
uses crt;uses crt;
uses crt;


var b, c, n:byte;
var b, c, n:byte;var b, c, n:byte;
var b, c, n:byte;


beg
begbeg
begin
inin
in


clrscr;
clrscr;clrscr;
clrscr;



repeat
repeatrepeat
repeat


write('Nhap tuoi cha: ');readln(b);
write('Nhap tuoi cha: ');readln(b); write('Nhap tuoi cha: ');readln(b);
write('Nhap tuoi cha: ');readln(b);


write('Nhap tuoi con: ');readln(c);
write('Nhap tuoi con: ');readln(c); write('Nhap tuoi con: ');readln(c);
write('Nhap tuoi con: ');readln(c);






if (b
if (bif (b
if (b-

-c<25) or (b<2*c) then
c<25) or (b<2*c) thenc<25) or (b<2*c) then
c<25) or (b<2*c) then



writeln('Du lieu khong hop le,nhap lai.');
writeln('Du lieu khong hop le,nhap lai.'); writeln('Du lieu khong hop le,nhap lai.');
writeln('Du lieu khong hop le,nhap lai.');


Great by: Nguyễn Trọng Hoàng Email:


until (b
until (buntil (b
until (b-

-c>=25) and (b>=2*c);
c>=25) and (b>=2*c);c>=25) and (b>=2*c);
c>=25) and (b>=2*c);


if b=2*c then
if b=2*c then if b=2*c then
if b=2*c then


writeln('Hien nay tuoi cha gap hai
writeln('Hien nay tuoi cha gap hai writeln('Hien nay tuoi cha gap hai
writeln('Hien nay tuoi cha gap hai lan tuoi con.')
lan tuoi con.') lan tuoi con.')
lan tuoi con.')


else

else else
else


if b>2*c then
if b>2*c then if b>2*c then
if b>2*c then


writeln('Sau ',b
writeln('Sau ',b writeln('Sau ',b
writeln('Sau ',b-

-2*c,' nam tuoi cha se gap doi tuoi
2*c,' nam tuoi cha se gap doi tuoi 2*c,' nam tuoi cha se gap doi tuoi
2*c,' nam tuoi cha se gap doi tuoi
con');
con');con');
con');


readln
readlnreadln
readln


end
endend
end.


.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





Bài 8.
program
program program
program Bai8
Bai8Bai8
Bai8;
;;
;


uses crt;
uses crt;uses crt;
uses crt;


var A, B, St, Luu :real;
var A, B, St, Luu :real;var A, B, St, Luu :real;
var A, B, St, Luu :real;



n:byte;
n:byte; n:byte;
n:byte;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap so tien gui: ');readln(a);
write('Nhap so tien gui: ');readln(a);write('Nhap so tien gui: ');readln(a);
write('Nhap so tien gui: ');readln(a);


write(
write(write(
write('Nhap so tien nhan: ');readln(b);
'Nhap so tien nhan: ');readln(b);'Nhap so tien nhan: ');readln(b);
'Nhap so tien nhan: ');readln(b);


luu:=A; n:=0; st:=a;
luu:=A; n:=0; st:=a;luu:=A; n:=0; st:=a;

luu:=A; n:=0; st:=a;




while St<=B do
while St<=B dowhile St<=B do
while St<=B do


begin
beginbegin
begin








St:
St:St:
St:=St+luu*0.0
=St+luu*0.0=St+luu*0.0
=St+luu*0.003
0303
03;
;;
;









n:=n+1;
n:=n+1;n:=n+1;
n:=n+1;


end
endend
end;
;;
;




writeln('So thang can la: ',n);
writeln('So thang can la: ',n);writeln('So thang can la: ',n);
writeln('So thang can la: ',n);


readln
readlnreadln
readln



end
endend
end.

.








VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





















Great by: Nguyễn Trọng Hoàng Email:





Ch−¬ng 4
Ch−¬ng 4Ch−¬ng 4
Ch−¬ng 4
:
: :
:





iÓu d÷ liÖu cã cÊu tróc
iÓu d÷ liÖu cã cÊu tróciÓu d÷ liÖu cã cÊu tróc
iÓu d÷ liÖu cã cÊu tróc














Bµi Thùc Hµnh Sè 3
Bµi Thùc Hµnh Sè 3Bµi Thùc Hµnh Sè 3
Bµi Thùc Hµnh Sè 3








*****
**********
*****








Bài 1.
program sum1;
program sum1;program sum1;
program sum1;


uses crt;
uses crt;uses crt;
uses crt;


const nmax=100;
const nmax=100;const nmax=100;
const nmax=100;


type Myarray=array[1 nmax] of integer;
type Myarray=array[1 nmax] of integer;type Myarray=array[1 nmax] of integer;
type Myarray=array[1 nmax] of integer;


var A:myarray;
var A:myarray;var A:myarray;
var A:myarray;


s,n,i,k:integer;
s,n,i,k:integer; s,n,i,k:integer;

s,n,i,k:integer;


posi,neg:integer;
posi,neg:integer; posi,neg:integer;
posi,neg:integer;


begin
beginbegin
begin


clrscr; randomize;
clrscr; randomize;clrscr; randomize;
clrscr; randomize;


write('Nhap n: ');readln(n);
write('Nhap n: ');readln(n);write('Nhap n: ');readln(n);
write('Nhap n: ');readln(n);


for i:=1 to n do A
for i:=1 to n do Afor i:=1 to n do A
for i:=1 to n do A[i]:=random(300)
[i]:=random(300)[i]:=random(300)
[i]:=random(300)-

-random(300);

random(300);random(300);
random(300);


for i:=1 to n do write(A[i]:5); writeln;
for i:=1 to n do write(A[i]:5); writeln;for i:=1 to n do write(A[i]:5); writeln;
for i:=1 to n do write(A[i]:5); writeln;


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


if A[i]>0 then posi:=posi+1
if A[i]>0 then posi:=posi+1if A[i]>0 then posi:=posi+1
if A[i]>0 then posi:=posi+1


else if A[i]<0 then
else if A[i]<0 thenelse if A[i]<0 then
else if A[i]<0 then


neg:=neg+1;
neg:=neg+1;neg:=neg+1;
neg:=neg+1;


writeln('Co ',posi,' so duong va ',neg,' so am trong

writeln('Co ',posi,' so duong va ',neg,' so am trong writeln('Co ',posi,' so duong va ',neg,' so am trong
writeln('Co ',posi,' so duong va ',neg,' so am trong
mang');
mang');mang');
mang');


write('Nhap k: ');readln(k);
write('Nhap k: ');readln(k);write('Nhap k: ');readln(k);
write('Nhap k: ');readln(k);


s:=0;
s:=0;s:=0;
s:=0;


for i:=1 to
for i:=1 to for i:=1 to
for i:=1 to n do
n don do
n do


if A[i] mod k = 0 then s:=s+A[i];
if A[i] mod k = 0 then s:=s+A[i];if A[i] mod k = 0 then s:=s+A[i];
if A[i] mod k = 0 then s:=s+A[i];


writeln('Tong can tinh la: ',s);

writeln('Tong can tinh la: ',s);writeln('Tong can tinh la: ',s);
writeln('Tong can tinh la: ',s);


readln
readlnreadln
readln


end
endend
end.

.





















K
KK
K



Great by: Nguyễn Trọng Hoàng Email:








VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





Bài này cho kết quả ngẫu nhiên nên kết quả của các bạn có thể khác.
Bài 2.
program mang2;

program mang2;program mang2;
program mang2;


uses crt;
uses crt;uses crt;
uses crt;


var A:array[1 100] of integer;
var A:array[1 100] of integer;var A:array[1 100] of integer;
var A:array[1 100] of integer;


n,i,j,max:integer;
n,i,j,max:integer; n,i,j,max:integer;
n,i,j,max:integer;


be
bebe
begin
gingin
gin


clrscr;
clrscr;clrscr;
clrscr;



write('Nhap so luong phan tu: ');readln(n);
write('Nhap so luong phan tu: ');readln(n);write('Nhap so luong phan tu: ');readln(n);
write('Nhap so luong phan tu: ');readln(n);


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


begin
beginbegin
begin


write('Nhap phan tu thu ',i,': '); readln(a[i]);
write('Nhap phan tu thu ',i,': '); readln(a[i]);write('Nhap phan tu thu ',i,': '); readln(a[i]);
write('Nhap phan tu thu ',i,': '); readln(a[i]);


end
endend
end;
;;
;


max:=a[1];
max:=a[1];max:=a[1];

max:=a[1];


for i:=2 to n do
for i:=2 to n dofor i:=2 to n do
for i:=2 to n do


if a[i]>a[i
if a[i]>a[iif a[i]>a[i
if a[i]>a[i-

-1] then max:=A[i];
1] then max:=A[i];1] then max:=A[i];
1] then max:=A[i];


for j:=1 to n do if a[j]=max then
for j:=1 to n do if a[j]=max thenfor j:=1 to n do if a[j]=max then
for j:=1 to n do if a[j]=max then


writeln('chi so phan tu lon nh
writeln('chi so phan tu lon nhwriteln('chi so phan tu lon nh
writeln('chi so phan tu lon nhat: ',j);
at: ',j);at: ',j);
at: ',j);


readln

readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





Chú ý: Các bạn sửa lại chương trình ñể ñưa ra kết quả hợp lí, các chỉ số của
phần tử lớn nhất cùng nằm trên một dòng.
















Great by: Nguyễn Trọng Hoàng Email:





Bµi Thùc Hµnh Sè 4
Bµi Thùc Hµnh Sè 4Bµi Thùc Hµnh Sè 4
Bµi Thùc Hµnh Sè 4






*****
**********
*****




Bài 1.
uses crt;

uses crt;uses crt;
uses crt;


var A:array[1 250] of integer;
var A:array[1 250] of integer;var A:array[1 250] of integer;
var A:array[1 250] of integer;


n,i,j,y,dem
n,i,j,y,dem n,i,j,y,dem
n,i,j,y,dem,t:integer;
,t:integer;,t:integer;
,t:integer;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


randomize;
randomize;randomize;
randomize;



write('Nhap n: ');readln(n);
write('Nhap n: ');readln(n);write('Nhap n: ');readln(n);
write('Nhap n: ');readln(n);


for i:=1 to n do A[i]:=random(300)
for i:=1 to n do A[i]:=random(300)for i:=1 to n do A[i]:=random(300)
for i:=1 to n do A[i]:=random(300)-

-random(300);
random(300);random(300);
random(300);


for i:=1 to n do write(A[i]:5);
for i:=1 to n do write(A[i]:5);for i:=1 to n do write(A[i]:5);
for i:=1 to n do write(A[i]:5);


writeln;
writeln;writeln;
writeln;


dem:=1;
dem:=1;dem:=1;
dem:=1;



for j:=n downto 2 do
for j:=n downto 2 dofor j:=n downto 2 do
for j:=n downto 2 do


for i:=1 to j
for i:=1 to j for i:=1 to j
for i:=1 to j-

-1 do
1 do1 do
1 do


if A[i]>A[i+1] then
if A[i]>A[i+1] then if A[i]>A[i+1] then
if A[i]>A[i+1] then




begin
begin begin
begin


t:=a[i];
t:=a[i]; t:=a[i];
t:=a[i];



a[i]:=a[i+1];
a[i]:=a[i+1]; a[i]:=a[i+1];
a[i]:=a[i+1];


A[i+1]:=t;
A[i+1]:=t; A[i+1]:=t;
A[i+1]:=t;


dem:=dem+1;
dem:=dem+1; dem:=dem+1;
dem:=dem+1;




end
endend
end;
;;
;


write('Sau khi dao ',dem,' lan');
write('Sau khi dao ',dem,' lan'); write('Sau khi dao ',dem,' lan');
write('Sau khi dao ',dem,' lan');



for i:=1 to n do
for i:=1 to n do for i:=1 to n do
for i:=1 to n do


write(A[i]:7);
write(A[i]:7); write(A[i]:7);
write(A[i]:7);




writeln;
writeln;writeln;
writeln;


readln
readln readln
readln




end
endend
end.

.



VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





Bài này cho kết quả là ngẫu nhiên.












Great by: Nguyễn Trọng Hoàng Email:





Bµi Thùc Hµnh Sè 5
Bµi Thùc Hµnh Sè 5Bµi Thùc Hµnh Sè 5

Bµi Thùc Hµnh Sè 5






*****
**********
*****




Bài 1.
program xau;
program xau;program xau;
program xau;


uses crt;
uses crt;uses crt;
uses crt;


var i, x:byte;
var i, x:byte;var i, x:byte;
var i, x:byte;





S: string;
S: string;S: string;
S: string;




kt:boolean;
kt:boolean;kt:boolean;
kt:boolean;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap xau:
write('Nhap xau: write('Nhap xau:
write('Nhap xau: ');readln(s);
');readln(s);');readln(s);
');readln(s);



x:=length(S);
x:=length(S);x:=length(S);
x:=length(S);


kt:=true;
kt:=true;kt:=true;
kt:=true;


for i:=1 to x div 2 do
for i:=1 to x div 2 dofor i:=1 to x div 2 do
for i:=1 to x div 2 do




if S[i]<>S[x
if S[i]<>S[xif S[i]<>S[x
if S[i]<>S[x-

-i+1] then kt:=false;
i+1] then kt:=false;i+1] then kt:=false;
i+1] then kt:=false;




if kt then write('Xau la palindrome')

if kt then write('Xau la palindrome')if kt then write('Xau la palindrome')
if kt then write('Xau la palindrome')




else write('Xau khong la palindrome');
else write('Xau khong la palindrome');else write('Xau khong la palindrome');
else write('Xau khong la palindrome');




readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô






Bài 2.
program Bai2;
program Bai2;program Bai2;
program Bai2;


uses crt;
uses crt;uses crt;
uses crt;


var S:string;
var S:string;var S:string;
var S:string;


i,n,dem:int
i,n,dem:int i,n,dem:int
i,n,dem:integer;
eger;eger;
eger;


ch:char;
ch:char; ch:char;
ch:char;



begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap xau: ');readln(S);
write('Nhap xau: ');readln(S);write('Nhap xau: ');readln(S);
write('Nhap xau: ');readln(S);


for i:=1 to length(S) do
for i:=1 to length(S) dofor i:=1 to length(S) do
for i:=1 to length(S) do


s[i]:=upcase(s[i]);
s[i]:=upcase(s[i]);s[i]:=upcase(s[i]);
s[i]:=upcase(s[i]);


for ch:='A' to 'Z' do
for ch:='A' to 'Z' dofor ch:='A' to 'Z' do
for ch:='A' to 'Z' do



begin
beginbegin
begin


dem:=0;
dem:=0;dem:=0;
dem:=0;


for i:=1 to length(s) do
for i:=1 to length(s) dofor i:=1 to length(s) do
for i:=1 to length(s) do


if s[i]=ch then dem:=dem+1;
if s[i]=ch then dem:=dem+1;if s[i]=ch then dem:=dem+1;
if s[i]=ch then dem:=dem+1;


Great by: Nguyễn Trọng Hoàng Email:


if dem>0 then
if dem>0 thenif dem>0 then
if dem>0 then


writeln('Trong xau co ',dem,' chu ',ch);

writeln('Trong xau co ',dem,' chu ',ch);writeln('Trong xau co ',dem,' chu ',ch);
writeln('Trong xau co ',dem,' chu ',ch);


end
endend
end;
;;
;


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô






Bài 3.
program anhem;
program anhem;program anhem;
program anhem;


uses crt;
uses crt;uses crt;
uses crt;


var S:string;
var S:string;var S:string;
var S:string;


i,n:integer;
i,n:integer; i,n:integer;
i,n:integer;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;



write('Nhap xau: ');readln(s);
write('Nhap xau: ');readln(s);write('Nhap xau: ');readln(s);
write('Nhap xau: ');readln(s);


while pos('anh',s)<> 0 do
while pos('anh',s)<> 0 dowhile pos('anh',s)<> 0 do
while pos('anh',s)<> 0 do


begin
beginbegin
begin


n:=pos('anh',s);
n:=pos('anh',s);n:=pos('anh',s);
n:=pos('anh',s);


delete(S,n,3);
delete(S,n,3);delete(S,n,3);
delete(S,n,3);


insert('em',s,n);
insert('em',s,n);insert('em',s,n);
insert('em',s,n);



END
ENDEND
END;
;;
;


write('Xau moi: ',s);
write('Xau moi: ',s);write('Xau moi: ',s);
write('Xau moi: ',s);


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô


























Great by: Nguyễn Trọng Hoàng Email:









Bµi tËp ch−¬ng 4
Bµi tËp ch−¬ng 4 Bµi tËp ch−¬ng 4
Bµi tËp ch−¬ng 4


1. Mảng là kiểu dữ liệu có cấu trúc bởi vì mảng là kiểu có cấu trúc ñược
ñề cập tới sớm nhất trong các ngôn ngữ lập trình. Nó ñược xây dựng
từ những kiểu dữ liệu ñã có theo quy tắc khuôn dạng do ngôn ngữ lập
trình cung cấp. Nó ñược dùng ñể chỉ ñịnh một nhóm ñối tượng cùng
một tính chất nào ñó.
2. Chúng ta phải khai báo kích thước mảng bởi vì ñể cách ñánh số các
phần tử của nó.
3. real, boolean, integer, longint.
4. Tham chiếu ñến phần tử của mảng một chiều ñược xác ñịnh bởi tên
mảng cùng với chỉ số, ñược viết trong cặp ngoặc [ ] (Ví dụ A[1]). Còn
tham chiếu ñến phần tử của mảng 2 chiều ñược xác ñịnh bởi tên mảng
cùng với 2 chỉ số ñược phân cách bởi dấu phẩy và viết trong cặp ngoặc
[ ] (A[1,2]).
Bài 5.
uses crt;
uses crt;uses crt;
uses crt;


var a:array[1 100] of integer;
var a:array[1 100] of integer;var a:array[1 100] of integer;
var a:array[1 100] of integer;



n,i,d:integer;
n,i,d:integer; n,i,d:integer;
n,i,d:integer;


c
c c
csc:boolean;
sc:boolean;sc:boolean;
sc:boolean;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap n: ');readln(n);
write('Nhap n: ');readln(n);write('Nhap n: ');readln(n);
write('Nhap n: ');readln(n);


for i:=1 to n do

for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


begin
beginbegin
begin


repeat
repeatrepeat
repeat


write('Nhap phan tu thu ',i,': ');
write('Nhap phan tu thu ',i,': ');write('Nhap phan tu thu ',i,': ');
write('Nhap phan tu thu ',i,': ');


readln(a[i]);
readln(a[i]);readln(a[i]);
readln(a[i]);


if abs(a[i])>1000 then writeln('Nhap so nho hon
if abs(a[i])>1000 then writeln('Nhap so nho hon if abs(a[i])>1000 then writeln('Nhap so nho hon
if abs(a[i])>1000 then writeln('Nhap so nho hon
1000');
1000');1000');
1000');



until abs(a[i])<=1000;
until abs(a[i])<=1000;until abs(a[i])<=1000;
until abs(a[i])<=1000; end;
end; end;
end;


csc:=false;
csc:=false;csc:=false;
csc:=false;


d:=a[2]
d:=a[2]d:=a[2]
d:=a[2]-

-a[1];
a[1];a[1];
a[1];


for i:=2 to
for i:=2 to for i:=2 to
for i:=2 to n do
n don do
n do



if a[i+1]
if a[i+1]if a[i+1]
if a[i+1]-

-a[i]=d then csc:=true;
a[i]=d then csc:=true;a[i]=d then csc:=true;
a[i]=d then csc:=true;


if csc then writeln('Day la cap so cong') else
if csc then writeln('Day la cap so cong') elseif csc then writeln('Day la cap so cong') else
if csc then writeln('Day la cap so cong') else


write('Day khong la cap so cong');
write('Day khong la cap so cong');write('Day khong la cap so cong');
write('Day khong la cap so cong');


readln
readlnreadln
readln end.
end. end.
end.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô



Great by: Nguyễn Trọng Hoàng Email:





Bai 6.
Bai 6.Bai 6.
Bai 6.


program bai6;
program bai6;program bai6;
program bai6;


uses crt;
uses crt;uses crt;
uses crt;


var A:array[1 100] of integer;
var A:array[1 100] of integer;var A:array[1 100] of integer;
var A:array[1 100] of integer;


i,n,dem,u,d:integer;
i,n,dem,u,d:integer; i,n,dem,u,d:integer;
i,n,dem,u,d:integer;



begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap so
write('Nhap sowrite('Nhap so
write('Nhap so luong phan tu: ');readln(n);
luong phan tu: ');readln(n); luong phan tu: ');readln(n);
luong phan tu: ');readln(n);


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


begin
beginbegin
begin


repeat

repeatrepeat
repeat


write('Nhap phan tu thu ',i,': ');
write('Nhap phan tu thu ',i,': ');write('Nhap phan tu thu ',i,': ');
write('Nhap phan tu thu ',i,': ');


readln(a[i]);
readln(a[i]);readln(a[i]);
readln(a[i]);


if abs(A[i])>1000 then write('Nhap so <1000 OK');
if abs(A[i])>1000 then write('Nhap so <1000 OK');if abs(A[i])>1000 then write('Nhap so <1000 OK');
if abs(A[i])>1000 then write('Nhap so <1000 OK');


until abs(A[i])<1000;
until abs(A[i])<1000;until abs(A[i])<1000;
until abs(A[i])<1000;


end
endend
end;
;;
;



dem:=0;
dem:=0;dem:=0;
dem:=0;


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


begin
beginbegin
begin


if a[i] mod 2= 0 then dem:=dem+1
if a[i] mod 2= 0 then dem:=dem+1if a[i] mod 2= 0 then dem:=dem+1
if a[i] mod 2= 0 then dem:=dem+1


end
endend
end;
;;
;


writeln('So luong so le: ',n
writeln('So luong so le: ',nwriteln('So luong so le: ',n

writeln('So luong so le: ',n-

-dem);
dem);dem);
dem);


writeln('So luong so chan: ',dem);
writeln('So luong so chan: ',dem);writeln('So luong so chan: ',dem);
writeln('So luong so chan: ',dem);


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


if a[i]>1 then
if a[i]>1 thenif a[i]>1 then
if a[i]>1 then


begin
beginbegin
begin


u:=2;
u:=2;u:=2;
u:=2;



while (u<=sqrt(A[i])) and
while (u<=sqrt(A[i])) and while (u<=sqrt(A[i])) and
while (u<=sqrt(A[i])) and


(A[i] mod u <> 0) do
(A[i] mod u <> 0) do(A[i] mod u <> 0) do
(A[i] mod u <> 0) do


u:=u+1;
u:=u+1;u:=u+1;
u:=u+1;


if u>sqrt(A[i]) then d:=d+1;
if u>sqrt(A[i]) then d:=d+1;if u>sqrt(A[i]) then d:=d+1;
if u>sqrt(A[i]) then d:=d+1;


end
endend
end;
;;
;


write('So luong so nguyen to: ',d);

write('So luong so nguyen to: ',d);write('So luong so nguyen to: ',d);
write('So luong so nguyen to: ',d);


Great by: Nguyễn Trọng Hoàng Email:


readln
readlnreadln
readln


end
endend
end.

.


VÝ D
VÝ DVÝ D
VÝ Dô
ôô
ô









Bài 7.
program bai7;
program bai7;program bai7;
program bai7;


uses crt;
uses crt;uses crt;
uses crt;


var n, i:word;
var n, i:word;var n, i:word;
var n, i:word; f, f1,f2:word;
f, f1,f2:word; f, f1,f2:word;
f, f1,f2:word;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;



repeat
repeatrepeat
repeat


write('Nhap N: ');readln(n);
write('Nhap N: ');readln(n);write('Nhap N: ');readln(n);
write('Nhap N: ');readln(n);


if n<2 then writeln('Nhap N>2 OK!');
if n<2 then writeln('Nhap N>2 OK!');if n<2 then writeln('Nhap N>2 OK!');
if n<2 then writeln('Nhap N>2 OK!');


until n>=2;
until n>=2;until n>=2;
until n>=2;


f1:=1;
f1:=1;f1:=1;
f1:=1;


f2:=2;
f2:=2;f2:=2;
f2:=2;



for i:=3 to n do
for i:=3 to n dofor i:=3 to n do
for i:=3 to n do


begin
beginbegin
begin


f:=f1+f2;
f:=f1+f2;f:=f1+f2;
f:=f1+f2;


f1:=f2;
f1:=f2;f1:=f2;
f1:=f2;


f2:=f;
f2:=f;f2:=f;
f2:=f;


end
endend
end;
;;
;



write('So fibonaxi thu
write('So fibonaxi thu write('So fibonaxi thu
write('So fibonaxi thu ',n,' la ' ,f);
',n,' la ' ,f);',n,' la ' ,f);
',n,' la ' ,f);


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô





Ch−¬ng tr×nh thùc hiÖn ®Õn

Ch−¬ng tr×nh thùc hiÖn ®Õn Ch−¬ng tr×nh thùc hiÖn ®Õn
Ch−¬ng tr×nh thùc hiÖn ®Õn


Nmax=10001.
Nmax=10001.Nmax=10001.
Nmax=10001.


Bài 8.
Bài 8.Bài 8.
Bài 8.


Chương trình thực hiện việc hoán ñổi vị trí dòng thứ i với dòng thứ N-i+1,
nghĩa là hoán ñổi vị trí dòng ñầu tiên với dòng cuối cùng của mảng hai
Great by: Nguyễn Trọng Hoàng Email:


chiều, dòng thứ hai từ trên xuống với dòng thứ hai từ dưới lên,… Việc hoán
ñổi vị trí dòng thứ i với dòng ñối xứng với nó ñược thực hiện khi i nhận giá
trị từ 1 ñến N, làm cho mỗi dòng ñược hoán ñổi vị trí 2 lần. Vì vậy mạng A
sau khi hoán ñổi không thay ñổi so với ban ñầu.
Bài 9.
program bai9;
program bai9;program bai9;
program bai9;


uses crt;

uses crt;uses crt;
uses crt;


var A:array[1 15,1 15] of integer;
var A:array[1 15,1 15] of integer;var A:array[1 15,1 15] of integer;
var A:array[1 15,1 15] of integer;




N, i, j, max, ind,
N, i, j, max, ind, N, i, j, max, ind,
N, i, j, max, ind, vsp:integer;
vsp:integer;vsp:integer;
vsp:integer;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap N: ');readln(n);
write('Nhap N: ');readln(n);write('Nhap N: ');readln(n);

write('Nhap N: ');readln(n);


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do




for j:=1 to n do
for j:=1 to n dofor j:=1 to n do
for j:=1 to n do






begin
beginbegin
begin






write('Nhap A[',i,',',j,']: ');
write('Nhap A[',i,',',j,']: ');write('Nhap A[',i,',',j,']: ');

write('Nhap A[',i,',',j,']: ');








readln(A[i,j]);
readln(A[i,j]);readln(A[i,j]);
readln(A[i,j]);






end
endend
end;
;;
;




for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do







begin
beginbegin
begin






max:=A[1,i];ind:=1;
max:=A[1,i];ind:=1; max:=A[1,i];ind:=1;
max:=A[1,i];ind:=1;






for j:=2 to n do
for j:=2 to n do for j:=2 to n do
for j:=2 to n do







if A[j,i] > max then
if A[j,i] > max then if A[j,i] > max then
if A[j,i] > max then










begin
beginbegin
begin










max:=A[j,i];

max:=A[j,i];max:=A[j,i];
max:=A[j,i];










ind:=j;
ind:=j;ind:=j;
ind:=j;








end
endend
end;
;;
;





vsp:=A[i,i];
vsp:=A[i,i];vsp:=A[i,i];
vsp:=A[i,i];




A[i,i]:=max;
A[i,i]:=max;A[i,i]:=max;
A[i,i]:=max;




A[ind,i]:=vsp;
A[ind,i]:=vsp;A[ind,i]:=vsp;
A[ind,i]:=vsp;




end
endend
end;
;;
;





for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do






begin
beginbegin
begin


writeln;
writeln; writeln;
writeln;






for j:=1 to n do write(A[i,j]:3);
for j:=1 to n do write(A[i,j]:3); for j:=1 to n do write(A[i,j]:3);
for j:=1 to n do write(A[i,j]:3);







end
endend
end;
;;
;




writeln;
writeln;writeln;
writeln;




readln
readlnreadln
readln


end
endend
end.

.



VÝ Dô
VÝ DôVÝ Dô
VÝ Dô


Great by: Nguyễn Trọng Hoàng Email:





Bài 10.
program bai10;
program bai10;program bai10;
program bai10;


uses crt;
uses crt;uses crt;
uses crt;


var S:string;
var S:string;var S:string;
var S:string;





i,dem,n:integer;
i,dem,n:integer;i,dem,n:integer;
i,dem,n:integer;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap xau: ');readln(S);
write('Nhap xau: ');readln(S); write('Nhap xau: ');readln(S);
write('Nhap xau: ');readln(S);


n:=length(S);
n:=length(S);n:=length(S);
n:=length(S);


dem:=0;
dem:=0;dem:=0;
dem:=0;



for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


if (s[i]>='0') and (s[i]<='9') then inc(dem);
if (s[i]>='0') and (s[i]<='9') then inc(dem);if (s[i]>='0') and (s[i]<='9') then inc(dem);
if (s[i]>='0') and (s[i]<='9') then inc(dem);


write('Co ',dem,' chu so trong xau vua nhap');
write('Co ',dem,' chu so trong xau vua nhap');write('Co ',dem,' chu so trong xau vua nhap');
write('Co ',dem,' chu so trong xau vua nhap');


readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô

VÝ Dô











Bai 11.
program bai11;
program bai11;program bai11;
program bai11;


uses crt;
uses crt;uses crt;
uses crt;


const
constconst
const max=60;
max=60; max=60;
max=60;



type Hocsinh = record
type Hocsinh = recordtype Hocsinh = record
type Hocsinh = record






hoten:string[30];
hoten:string[30];hoten:string[30];
hoten:string[30];






ngaysinh:string[10];
ngaysinh:string[10];ngaysinh:string[10];
ngaysinh:string[10];






diachi:string[50];
diachi:string[50];diachi:string[50];
diachi:string[50];







toan, van:real;
toan, van:real;toan, van:real;
toan, van:real;






xeploai:char;
xeploai:char;xeploai:char;
xeploai:char;






end
endend
end;
;;
;



var lop:array[1 max] of hocsinh;
var lop:array[1 max] of hocsinh;var lop:array[1 max] of hocsinh;
var lop:array[1 max] of hocsinh;






N, i:byte;
N, i:byte;N, i:byte;
N, i:byte;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap so luong hoc sinh: ');readln(n);
write('Nhap so luong hoc sinh: ');readln(n);write('Nhap so luong hoc sinh: ');readln(n);
write('Nhap so luong hoc sinh: ');readln(n);



Great by: Nguyễn Trọng Hoàng Email:


for i:=1 to n
for i:=1 to n for i:=1 to n
for i:=1 to n do
dodo
do


with lop[i] do
with lop[i] dowith lop[i] do
with lop[i] do {Chó ý c©u lÖnh nµy}
{Chó ý c©u lÖnh nµy} {Chó ý c©u lÖnh nµy}
{Chó ý c©u lÖnh nµy}


begin
beginbegin
begin


writeln('Nhap so lieu hoc sinh thu ',i,':');
writeln('Nhap so lieu hoc sinh thu ',i,':');writeln('Nhap so lieu hoc sinh thu ',i,':');
writeln('Nhap so lieu hoc sinh thu ',i,':');


write('Ho va ten: ');readln(hoten);
write('Ho va ten: ');readln(hoten);write('Ho va ten: ');readln(hoten);
write('Ho va ten: ');readln(hoten);



write('Ngay sinh: ');readln(ngaysinh);
write('Ngay sinh: ');readln(ngaysinh);write('Ngay sinh: ');readln(ngaysinh);
write('Ngay sinh: ');readln(ngaysinh);


write('Dia chi : ');readln(diachi);
write('Dia chi : ');readln(diachi);write('Dia chi : ');readln(diachi);
write('Dia chi : ');readln(diachi);


write('Diem toan: ');readln(toan);
write('Diem toan: ');readln(toan);write('Diem toan: ');readln(toan);
write('Diem toan: ');readln(toan);


write('Diem van : '
write('Diem van : 'write('Diem van : '
write('Diem van : ');readln(van);
);readln(van););readln(van);
);readln(van);


if toan+van>=18 then xeploai:='A';
if toan+van>=18 then xeploai:='A';if toan+van>=18 then xeploai:='A';
if toan+van>=18 then xeploai:='A';


if (toan+van>=14) and (toan+van<18) then

if (toan+van>=14) and (toan+van<18) thenif (toan+van>=14) and (toan+van<18) then
if (toan+van>=14) and (toan+van<18) then


xeploai:='B';
xeploai:='B'; xeploai:='B';
xeploai:='B';


if (toan+van>=10) and (toan+van<14) then
if (toan+van>=10) and (toan+van<14) thenif (toan+van>=10) and (toan+van<14) then
if (toan+van>=10) and (toan+van<14) then


xeploai:='C';
xeploai:='C';xeploai:='C';
xeploai:='C';


if (toan+van<10) then
if (toan+van<10) thenif (toan+van<10) then
if (toan+van<10) then


xeploai:='D';
xeploai:='D';xeploai:='D';
xeploai:='D';


end

endend
end;
;;
;


clrscr;
clrscr;clrscr;
clrscr;


writeln('Danh sach hoc sinh:');
writeln('Danh sach hoc sinh:');writeln('Danh sach hoc sinh:');
writeln('Danh sach hoc sinh:');


for i:=1 to
for i:=1 to for i:=1 to
for i:=1 to n do
n don do
n do


with lop[i] do
with lop[i] dowith lop[i] do
with lop[i] do


writeln(hoten:30,'
writeln(hoten:30,'writeln(hoten:30,'

writeln(hoten:30,'-

- xep loai: ',xeploai);
xep loai: ',xeploai); xep loai: ',xeploai);
xep loai: ',xeploai);


writeln('Danh sach hoc sinh loai A:');
writeln('Danh sach hoc sinh loai A:');writeln('Danh sach hoc sinh loai A:');
writeln('Danh sach hoc sinh loai A:');


for i:=1 to n do
for i:=1 to n dofor i:=1 to n do
for i:=1 to n do


with lop[i] do
with lop[i] do with lop[i] do
with lop[i] do


if xeploai='A' then
if xeploai='A' thenif xeploai='A' then
if xeploai='A' then


writeln(hoten:30);
writeln(hoten:30);writeln(hoten:30);
writeln(hoten:30);



readln
readlnreadln
readln


end
endend
end.

.


VÝ Dô
VÝ DôVÝ Dô
VÝ Dô


NhËp vµo
NhËp vµoNhËp vµo
NhËp vµo





Great by: Nguyễn Trọng Hoàng Email:






KÕt qu¶
KÕt qu¶KÕt qu¶
KÕt qu¶
















































Great by: Nguyễn Trọng Hoàng Email:


Ch−¬ng 5
Ch−¬ng 5Ch−¬ng 5
Ch−¬ng 5
:

: :
:





hao t¸c víi
hao t¸c víi hao t¸c víi
hao t¸c víi tÖp
tÖptÖp
tÖp








Bµi tËp ch−¬ng
Bµi tËp ch−¬ngBµi tËp ch−¬ng
Bµi tËp ch−¬ng









1. Một số

trường hợp phải dùng tệp: lưu trữ lượng thông tin lớn, dùng
lâu dài, ít thay ñổi như tên người trong một cơ quan, hồ sơ của sinh
viên, lương cán bộ,
2. SGK
3. Phải mở tệp trước khi ñọc tệp vì trước khi sử dụng tệp phải có câu
lệnh mở tệp ñể trình dịch biết thực hiện mục ñích mở tệp ñể ñọc hay
ghi, ñồng thời ñặt con trỏ tệp vào vị trí thích hợp
4. Phải dùng lệnh ñóng tệp sau hi ñã kết thúc ghi dữ liệu vào tệp ñể thống
tất việc ghi dữ liệu ra tệp. Không có câu lệnh ñóng tệp thì chương trình
sẽ không thể ghi ñược dữ liệu vào tệp.



























































T
TT
T



Great by: Nguyễn Trọng Hoàng Email:


Ch−¬ng 6
Ch−¬ng 6Ch−¬ng 6
Ch−¬ng 6
:
: :
:


h−¬ng tr×nh con vµ lËp tr×nh cã
h−¬ng tr×nh con vµ lËp tr×nh cã h−¬ng tr×nh con vµ lËp tr×nh cã
h−¬ng tr×nh con vµ lËp tr×nh cã



cÊu tróc
cÊu tróccÊu tróc
cÊu tróc









Bµi Thùc Hµnh Sè 6
Bµi Thùc Hµnh Sè 6Bµi Thùc Hµnh Sè 6
Bµi Thùc Hµnh Sè 6






*****
**********
*****








Chương trình
program
program program
program thuchanh6
thuchanh6thuchanh6
thuchanh6;
;;
;


uses crt;
uses crt; uses crt;
uses crt;


type str = string[79];
type str = string[79];type str = string[79];
type str = string[79];


var S1, S2:str;
var S1, S2:str;var S1, S2:str;
var S1, S2:str;





do
dodo
dong:byte;
ng:byte;ng:byte;
ng:byte;




dung:boolean;
dung:boolean;dung:boolean;
dung:boolean;


procedure catdan(s1:str; var s2: str);
procedure catdan(s1:str; var s2: str);procedure catdan(s1:str; var s2: str);
procedure catdan(s1:str; var s2: str);


begin
beginbegin
begin


s2:=copy(s1,2,length(s1)
s2:=copy(s1,2,length(s1)s2:=copy(s1,2,length(s1)
s2:=copy(s1,2,length(s1)-

-1)+S1[1];
1)+S1[1];1)+S1[1];

1)+S1[1];


end;
end;end;
end;


procedure cangiua(var s:str);
procedure cangiua(var s:str);procedure cangiua(var s:str);
procedure cangiua(var s:str);


var n, i:integer;
var n, i:integer;var n, i:integer;
var n, i:integer;


begin
beginbegin
begin


n:=length(s);
n:=length(s);n:=length(s);
n:=length(s);


n:=(80
n:=(80n:=(80

n:=(80-

-n) div 2;
n) div 2;n) div 2;
n) div 2;


for i:=1 to n do s:=' '+s;
for i:=1 to n do s:=' '+s;for i:=1 to n do s:=' '+s;
for i:=1 to n do s:=' '+s;


end;
end;end;
end;


procedure chuchay(s1:str; dong
procedure chuchay(s1:str; dongprocedure chuchay(s1:str; dong
procedure chuchay(s1:str; dong:byte);
:byte);:byte);
:byte);


var s2:str;
var s2:str;var s2:str;
var s2:str;





dung:boolean;
dung:boolean;dung:boolean;
dung:boolean;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


cangiua(s1);
cangiua(s1);cangiua(s1);
cangiua(s1);


clrscr;
clrscr;clrscr;
clrscr;


dung:=false;
dung:=false;dung:=false;
dung:=false;



while not(dung) do
while not(dung) dowhile not(dung) do
while not(dung) do


begin
beginbegin
begin


gotoxy(1,dong);
gotoxy(1,dong);gotoxy(1,dong);
gotoxy(1,dong);


write(s1);
write(s1);write(s1);
write(s1);


delay(100);
delay(100);delay(100);
delay(100);


catdan(s1,s2);
catdan(s1,s2);catdan(s1,s2);
catdan(s1,s2);



s1:=s2;
s1:=s2;s1:=s2;
s1:=s2;





C
CC
C



24
Great by: Nguyễn Trọng Hoàng Email:


dung:=keypressed;
dung:=keypressed;dung:=keypressed;
dung:=keypressed;


end;
end;end;
end;


end;

end;end;
end;


begin
beginbegin
begin


clrscr;
clrscr;clrscr;
clrscr;


write('Nhap xau : ');readln(s1);
write('Nhap xau : ');readln(s1);write('Nhap xau : ');readln(s1);
write('Nhap xau : ');readln(s1);


write('Nha
write('Nhawrite('Nha
write('Nhap dong: ');readln(dong);
p dong: ');readln(dong);p dong: ');readln(dong);
p dong: ');readln(dong);


chuchay(s1,dong);
chuchay(s1,dong);chuchay(s1,dong);
chuchay(s1,dong);



readln
readlnreadln
readln


end.
end.end.
end.





































×