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); Great by: Nguyễn Trọng Hoàng Email: readln
readlnreadln
readln end
endend
end.
. VÝ Dô
VÝ DôVÝ Dô
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!');
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
*****
**********
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;
;;
;
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.
.
. 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 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;
;;
; readln
readlnreadln
readln end
endend
end.
. VÝ Dô
VÝ DôVÝ Dô
VÝ Dô
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);
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);
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:=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ô
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;
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);
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.
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');
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;
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
. 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;
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;
;;
;
end
endend
end.
. VÝ Dô
VÝ DôVÝ Dô
VÝ Dô
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 *****
**********
*****
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);
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);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;
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];
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.
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;
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];
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.
.
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;
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')
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 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);
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;
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ô 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;
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');
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ô
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
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
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);
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;
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;
;;
;
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;
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,']: ');
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
max:=A[j,i];max:=A[j,i];
max:=A[j,i];
ind:=j;
ind:=j;ind:=j;
ind:=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 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); 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;
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ô
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];
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); 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
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,'
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: Great by: Nguyễn Trọng Hoàng Email: Ch−¬ng 5
Ch−¬ng 5Ch−¬ng 5
Ch−¬ng 5
:
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ã
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;
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
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;
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;
readln
readlnreadln
readln end.
end.end.
end.