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
: :
: ộ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
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
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
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;
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;
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')
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;
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); Edited by Foxit Reader
Copyright(C) by Foxit Software Company,2005-2007
For Evaluation Only.
Great by: Nguyễn Trọng Hoàng Email: readln
readlnreadln
readln end
endend
end.
.
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!');
VÝ Dô
VÝ DôVÝ Dô
VÝ Dô
: ấ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
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:=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.
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;
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);
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ô
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);
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;
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;
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.
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;
begin
beginbegin
begin
n:=n+1;
n:=n+1;n:=n+1;
n:=n+1;
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ô
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
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
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.'); Edited by Foxit Reader
Copyright(C) by Foxit Software Company,2005-2007
For Evaluation Only.
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
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;
;;
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
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ô
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
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;
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;
K
KK
K
Great by: Nguyễn Trọng Hoàng Email:
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
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ô
*****
**********
*****
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;
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
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;
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.
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
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;
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
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;
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
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ó.
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,': ');
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');
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);
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]>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;
. 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;
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;
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,
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
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
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;
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;
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;
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');
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];
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 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);
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:');
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ô
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
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;
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;
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;
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
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.