29
Great by: Nguyn Trng Hoàng Email: [email protected] 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 11 Häc 11 Häc 11

Giải bài tập Tin học 11 SGK

Embed Size (px)

DESCRIPTION

Hướng dẫn giải bt sgk tin học 11

Citation preview

Page 1: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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 11Häc 11Häc 11Häc 11

Page 2: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

Ch−¬ng 1Ch−¬ng 1Ch−¬ng 1Ch−¬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ËpBµi tËpBµi tËpBµi tËp 1. Người ta phải xây dựng ngôn ngữ lập trình bậc cao vì - Ngôn ngữ lập trình bậc cao gần gũi với tự nhiên hơn, thuận tiện cho

ñông ñảo người lập trình. - Ngôn ngữ lập trình bậc cao nói chung không phụ thuộc vào loại máy,

cùng một chương trình có thể thực hiện ở nhiều máy khác nhau. - Chương trình viết bằng ngôn ngữ bậc cao dễ hiểu, dễ hiệu chỉnh và dễ

nâng cấp hơn. - Ngôn ngữ lập trình bậc cao cho phép làm việc với nhiều kiểu dữ liệu và

cách tổ chức dữ liệu ña dạng, thuận tiện cho mô tả thuật toán. 2. Chương trình dịch là chương trình ñặc biệt, có chức năng chuyển ñổi

chương trình ñược viết trên ngôn ngữ lập trình bậc cao thành chương trình th ực hiện ñược trên máy tính.

3. - Biên dịch: duyệt, kiểm tra, phát hiện lỗi, xác ñịnh chương trình nguồn

có dịch ñược không. Dịch toàn bộ chương trình nguồn thành một chương trình ñích có thể thực hiện trên máy và có thể lưu trữ lại ñể sử dụng về sau khi cần.

- Thông dịch: lần lượt dịch từng câu lệnh ra ngôn ngữ máy rồi thực hiên ngay câu lệnh vừa dịch ñược hoặc thông báo lỗi nếu không dịch ñược.

4. Các ñiểm khác nhau giữa tên dành riêng và tên chuẩn: tên dành riêng không ñược dùng khác với ý nghĩa xác ñịnh, tên chuẩn có thể dùng với ý nghĩa khác.

5. ðúng: tamgiac, bai5a, xemxonxiu_ngu... 6. C: 6,23→ 6.23

E: A20 tên chưa có giá trị G: 64 + H: ‘C → ‘C’I: ‘TRUE’ “true” là h ằng logic.

MMMM

Page 3: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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

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

Bµi Thùc Hµnh Sè 1Bµi Thùc Hµnh Sè 1Bµi Thùc Hµnh Sè 1Bµ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 cruses cruses cruses 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; beginbeginbeginbegin 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))) thenthenthenthen 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')

CCCC

Page 4: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] else write('Khong thuelse write('Khong thuelse write('Khong thuelse write('Khong thuoc');oc');oc');oc');

readlnreadlnreadlnreadln endendendend....

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; beginbeginbeginbegin

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) thenif (abs(y)<=1) and (abs(x)<=1) thenif (abs(y)<=1) and (abs(x)<=1) thenif (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 gaif kt then write('Diem vua nhap thuoc phan gaif kt then write('Diem vua nhap thuoc phan gaif 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'); readlnreadlnreadlnreadln endendendend....

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; repeatrepeatrepeatrepeat 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; wriwriwriwrite('Diente('Diente('Diente('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);

Page 5: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] readlnreadlnreadlnreadln

endendendend....

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; repeatrepeatrepeatrepeat 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 tocwrite('Van tocwrite('Van tocwrite('Van toc: ',v:8:3);: ',v:8:3);: ',v:8:3);: ',v:8:3); readlnreadlnreadlnreadln endendendend....

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

Page 6: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

Ch−¬ng 3Ch−¬ng 3Ch−¬ng 3Ch−¬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è 2Bµi Thùc Hµnh Sè 2Bµi Thùc Hµnh Sè 2Bµi Thùc Hµnh Sè 2 --------------------------------------------------------------------********************-------------------------------------------------------------------- 1. SGK 2. Câu lệnh ghép là một câu lệnh ñược hợp thành từ nhiều câu lệnh thành phần. Câu lệnh ghép nhằm thực hiện thao tác gồm nhiều thao tác thành phần. Mỗi thao tác thành phần ứng với một câu lệnh ñơn hoặc một câu lẹnh ghép khác. Câu lệnh ghép là một trong các yếu tố ñể tạo khả năng chương trình có cấu trúc. Các câu lệnh ñặt giữa begin và end; Bài 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; beginbeginbeginbegin 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 BeginBeginBeginBegin

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+1N:=N+1N:=N+1N:=N+1;;;; EndEndEndEnd;;;;

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 EndEndEndEnd....

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

CCCC

Page 7: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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; beginbeginbeginbegin 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); endendendend;;;; 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 beginbeginbeginbegin 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); endendendend;;;;

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); endendendend;;;;

readlnreadlnreadlnreadln endendendend....

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

b)b)b)b) program bai4program bai4program bai4program bai4bbbb;;;; 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; beginbeginbeginbegin 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(xa)+sqr(xa)+sqr(xa)+sqr(x----b))<r thenb))<r thenb))<r thenb))<r then

begin begin begin begin

Page 8: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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); endendendend

elseelseelseelse

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); endendendend;;;;

readlnreadlnreadlnreadln

endendendend....

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

Bài 5. a)a)a)a) Program Program Program Program baibaibaibai5a;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; BeginBeginBeginBegin

Clrscr;Clrscr;Clrscr;Clrscr; for i:=1 to n dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do Y:=i/(i+1);Y:=i/(i+1);Y:=i/(i+1);Y:=i/(i+1); Write('Tong Y: ',yWrite('Tong Y: ',yWrite('Tong Y: ',yWrite('Tong Y: ',y:9:3:9:3:9:3:9:3);););); ReadlnReadlnReadlnReadln

EndEndEndEnd....

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

b)b)b)b) progrprogrprogrprogram am am am baibaibaibai5b;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; beginbeginbeginbegin clrscr;clrscr;clrscr;clrscr; sh:=1/2; sh:=1/2; sh:=1/2; sh:=1/2; n:=2; n:=2; n:=2; n:=2;

Page 9: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] 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 do16 do16 do16 do beginbeginbeginbegin 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; endendendend;;;; 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); readlnreadlnreadlnreadln

endendendend....

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

Bài Bài Bài Bài 6.6.6.6. prograprograprograprogram m m m Bai6Bai6Bai6Bai6;;;; uses crt;uses crt;uses crt;uses crt; var x, y:byte;var x, y:byte;var x, y:byte;var x, y:byte; beginbeginbeginbegin

clrscr;clrscr;clrscr;clrscr; for x:=1 to 36 dofor x:=1 to 36 dofor x:=1 to 36 dofor x:=1 to 36 do for y:=0 to 20 dofor y:=0 to 20 dofor y:=0 to 20 dofor y:=0 to 20 do

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

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'); endendendend;;;;

readlnreadlnreadlnreadln endendendend....

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

Bài 7. program program program program Bai7Bai7Bai7Bai7;;;; 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; begbegbegbeginininin clrscr;clrscr;clrscr;clrscr; repeatrepeatrepeatrepeat 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 (bif (bif (bif (b----c<25) or (b<2*c) thenc<25) or (b<2*c) thenc<25) or (b<2*c) thenc<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.');

Page 10: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] until (buntil (buntil (buntil (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'); readlnreadlnreadlnreadln endendendend....

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

Bài 8. program program program program Bai8Bai8Bai8Bai8;;;; 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; beginbeginbeginbegin 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 dowhile St<=B dowhile St<=B dowhile St<=B do beginbeginbeginbegin

St:St:St:St:=St+luu*0.0=St+luu*0.0=St+luu*0.0=St+luu*0.003030303;;;; n:=n+1;n:=n+1;n:=n+1;n:=n+1;

endendendend;;;;

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

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

Page 11: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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

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

Bµi Thùc Hµnh Sè 3Bµi Thùc Hµnh Sè 3Bµi Thùc Hµnh Sè 3Bµ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; beginbeginbeginbegin 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 Afor i:=1 to n do Afor i:=1 to n do Afor 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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do if A[i]>0 then posi:=posi+1if A[i]>0 then posi:=posi+1if A[i]>0 then posi:=posi+1if A[i]>0 then posi:=posi+1 else if A[i]<0 thenelse if A[i]<0 thenelse if A[i]<0 thenelse 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 don don don 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); readlnreadlnreadlnreadln endendendend....

KKKK

Page 12: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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; bebebebegingingingin 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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do beginbeginbeginbegin 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]); endendendend;;;;

max:=a[1];max:=a[1];max:=a[1];max:=a[1]; for i:=2 to n dofor i:=2 to n dofor i:=2 to n dofor i:=2 to n do if a[i]>a[iif a[i]>a[iif a[i]>a[iif 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 thenfor j:=1 to n do if a[j]=max thenfor j:=1 to n do if a[j]=max thenfor j:=1 to n do if a[j]=max then writeln('chi so phan tu lon nhwriteln('chi so phan tu lon nhwriteln('chi so phan tu lon nhwriteln('chi so phan tu lon nhat: ',j);at: ',j);at: ',j);at: ',j); readlnreadlnreadlnreadln endendendend....

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.

Page 13: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

Bµi Thùc Hµnh Sè 4Bµi Thùc Hµnh Sè 4Bµi Thùc Hµnh Sè 4Bµ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; beginbeginbeginbegin 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 dofor j:=n downto 2 dofor j:=n downto 2 dofor 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 do1 do1 do1 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; endendendend;;;;

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

endendendend....

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

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

Page 14: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

Bµi Thùc Hµnh Sè 5Bµi Thùc Hµnh Sè 5Bµi Thùc Hµnh Sè 5Bµ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; beginbeginbeginbegin 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 dofor i:=1 to x div 2 dofor i:=1 to x div 2 dofor i:=1 to x div 2 do if S[i]<>S[xif S[i]<>S[xif S[i]<>S[xif 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'); readlnreadlnreadlnreadln endendendend....

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; beginbeginbeginbegin 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) dofor i:=1 to length(S) dofor i:=1 to length(S) dofor 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' dofor ch:='A' to 'Z' dofor ch:='A' to 'Z' dofor ch:='A' to 'Z' do beginbeginbeginbegin dem:=0;dem:=0;dem:=0;dem:=0;

for i:=1 to length(s) dofor i:=1 to length(s) dofor i:=1 to length(s) dofor 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;

Page 15: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] if dem>0 thenif dem>0 thenif dem>0 thenif 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); endendendend;;;; readlnreadlnreadlnreadln

endendendend....

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; beginbeginbeginbegin

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 dowhile pos('anh',s)<> 0 dowhile pos('anh',s)<> 0 dowhile pos('anh',s)<> 0 do beginbeginbeginbegin 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); ENDENDENDEND;;;; write('Xau moi: ',s);write('Xau moi: ',s);write('Xau moi: ',s);write('Xau moi: ',s); readlnreadlnreadlnreadln endendendend....

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

Page 16: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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; beginbeginbeginbegin 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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do

beginbeginbeginbegin repeatrepeatrepeatrepeat 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 don don don 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') elseif csc then writeln('Day la cap so cong') elseif csc then writeln('Day la cap so cong') elseif 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'); readlnreadlnreadlnreadln end. end. end. end.

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

Page 17: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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; beginbeginbeginbegin

clrscr;clrscr;clrscr;clrscr; write('Nhap sowrite('Nhap sowrite('Nhap sowrite('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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do beginbeginbeginbegin repeatrepeatrepeatrepeat 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; endendendend;;;; dem:=0;dem:=0;dem:=0;dem:=0; for i:=1 to n dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do beginbeginbeginbegin if a[i] mod 2= 0 then dem:=dem+1if a[i] mod 2= 0 then dem:=dem+1if a[i] mod 2= 0 then dem:=dem+1if a[i] mod 2= 0 then dem:=dem+1 endendendend;;;; writeln('So luong so le: ',nwriteln('So luong so le: ',nwriteln('So luong so le: ',nwriteln('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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do if a[i]>1 thenif a[i]>1 thenif a[i]>1 thenif a[i]>1 then beginbeginbeginbegin

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;

endendendend;;;; 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);

Page 18: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] readlnreadlnreadlnreadln

endendendend....

VÝ DVÝ DVÝ DVÝ 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; beginbeginbeginbegin

clrscr;clrscr;clrscr;clrscr; repeatrepeatrepeatrepeat 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 dofor i:=3 to n dofor i:=3 to n dofor i:=3 to n do beginbeginbeginbegin 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; endendendend;;;; 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); readlnreadlnreadlnreadln endendendend....

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

Page 19: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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; beginbeginbeginbegin

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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do

for j:=1 to n dofor j:=1 to n dofor j:=1 to n dofor j:=1 to n do beginbeginbeginbegin 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]); endendendend;;;;

for i:=1 to n dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do beginbeginbeginbegin 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 beginbeginbeginbegin max:=A[j,i];max:=A[j,i];max:=A[j,i];max:=A[j,i]; ind:=j;ind:=j;ind:=j;ind:=j; endendendend;;;; 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; endendendend;;;; for i:=1 to n dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do beginbeginbeginbegin 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);

endendendend;;;; writeln;writeln;writeln;writeln; readlnreadlnreadlnreadln

endendendend....

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

Page 20: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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; beginbeginbeginbegin 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 dofor i:=1 to n dofor i:=1 to n dofor 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'); readlnreadlnreadlnreadln endendendend....

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; constconstconstconst max=60; max=60; max=60; max=60;

type Hocsinh = recordtype Hocsinh = recordtype Hocsinh = recordtype 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; endendendend;;;; 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; beginbeginbeginbegin 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);

Page 21: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] for i:=1 to n for i:=1 to n for i:=1 to n for i:=1 to n dodododo

with lop[i] dowith lop[i] dowith lop[i] dowith 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} beginbeginbeginbegin 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) thenif (toan+van>=14) and (toan+van<18) thenif (toan+van>=14) and (toan+van<18) thenif (toan+van>=14) and (toan+van<18) then xeploai:='B'; xeploai:='B'; xeploai:='B'; xeploai:='B';

if (toan+van>=10) and (toan+van<14) thenif (toan+van>=10) and (toan+van<14) thenif (toan+van>=10) and (toan+van<14) thenif (toan+van>=10) and (toan+van<14) then xeploai:='C';xeploai:='C';xeploai:='C';xeploai:='C'; if (toan+van<10) thenif (toan+van<10) thenif (toan+van<10) thenif (toan+van<10) then xeploai:='D';xeploai:='D';xeploai:='D';xeploai:='D'; endendendend;;;; 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 don don don do with lop[i] dowith lop[i] dowith lop[i] dowith 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 dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do with lop[i] do with lop[i] do with lop[i] do with lop[i] do if xeploai='A' thenif xeploai='A' thenif xeploai='A' thenif xeploai='A' then writeln(hoten:30);writeln(hoten:30);writeln(hoten:30);writeln(hoten:30); readlnreadlnreadlnreadln endendendend....

VÝ DôVÝ DôVÝ DôVÝ Dô NhËp vµoNhËp vµoNhËp vµoNhËp vµo

Page 22: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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

Page 23: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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

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

Bµi tËp ch−¬ngBµi tËp ch−¬ngBµi tËp ch−¬ngBµ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.

TTTT

Page 24: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

Ch−¬ng 6Ch−¬ng 6Ch−¬ng 6Ch−¬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óccÊu tróccÊu tróccÊu tróc

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

--------------------------------------------------------------------********************-------------------------------------------------------------------- Chương trình program program program program thuchanh6thuchanh6thuchanh6thuchanh6;;;; 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; dodododong: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); beginbeginbeginbegin

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; beginbeginbeginbegin n:=length(s);n:=length(s);n:=length(s);n:=length(s); n:=(80n:=(80n:=(80n:=(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; dongprocedure chuchay(s1:str; dongprocedure chuchay(s1:str; dongprocedure 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; beginbeginbeginbegin 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) dowhile not(dung) dowhile not(dung) dowhile not(dung) do beginbeginbeginbegin 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;

CCCC

24

Page 25: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] dung:=keypressed;dung:=keypressed;dung:=keypressed;dung:=keypressed;

end;end;end;end; end;end;end;end; beginbeginbeginbegin

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('Nhawrite('Nhawrite('Nhawrite('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); readlnreadlnreadlnreadln

end.end.end.end.

Page 26: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

Bµi Thùc Hµnh Sè 7Bµi Thùc Hµnh Sè 7Bµi Thùc Hµnh Sè 7Bµi Thùc Hµnh Sè 7 --------------------------------------------------------------------********************-------------------------------------------------------------------- program ttamgiac;program ttamgiac;program ttamgiac;program ttamgiac; uses crt;uses crt;uses crt;uses crt; const eps=1.0econst eps=1.0econst eps=1.0econst eps=1.0e----6;6;6;6;

typetypetypetype diem=recorddiem=recorddiem=recorddiem=record x, y:real;x, y:real;x, y:real;x, y:real; end;end;end;end; tamgiac=record tamgiac=record tamgiac=record tamgiac=record a, b, c:diem;a, b, c:diem;a, b, c:diem;a, b, c:diem; end;end;end;end; var T:tamgiac;var T:tamgiac;var T:tamgiac;var T:tamgiac; d, cn, v: boolean;d, cn, v: boolean;d, cn, v: boolean;d, cn, v: boolean; n, i, deu, can, vuong:word;n, i, deu, can, vuong:word;n, i, deu, can, vuong:word;n, i, deu, can, vuong:word; f,g:text;f,g:text;f,g:text;f,g:text; function khcach(P, Q: Diem):real;function khcach(P, Q: Diem):real;function khcach(P, Q: Diem):real;function khcach(P, Q: Diem):real; beginbeginbeginbegin khcach:=sqrt((P.xkhcach:=sqrt((P.xkhcach:=sqrt((P.xkhcach:=sqrt((P.x----Q.x)*(p.xQ.x)*(p.xQ.x)*(p.xQ.x)*(p.x----q.x)+(p.yq.x)+(p.yq.x)+(p.yq.x)+(p.y----Q.y)*(p.yQ.y)*(p.yQ.y)*(p.yQ.y)*(p.y----Q.y));Q.y));Q.y));Q.y)); end;end;end;end; procedure daicanh(var R:tamgiac; var a, b, c:real);procedure daicanh(var R:tamgiac; var a, b, c:real);procedure daicanh(var R:tamgiac; var a, b, c:real);procedure daicanh(var R:tamgiac; var a, b, c:real); bbbbeginegineginegin a:=khcach(R.B, R.C);a:=khcach(R.B, R.C);a:=khcach(R.B, R.C);a:=khcach(R.B, R.C); b:=khcach(R.A, R.C);b:=khcach(R.A, R.C);b:=khcach(R.A, R.C);b:=khcach(R.A, R.C); c:=khcach(R.A, R.B);c:=khcach(R.A, R.B);c:=khcach(R.A, R.B);c:=khcach(R.A, R.B); end;end;end;end; procedure tinhchat(var R: tamgiac; var procedure tinhchat(var R: tamgiac; var procedure tinhchat(var R: tamgiac; var procedure tinhchat(var R: tamgiac; var deu,can,vuong:boolean);deu,can,vuong:boolean);deu,can,vuong:boolean);deu,can,vuong:boolean); var a, b, c:real;var a, b, c:real;var a, b, c:real;var a, b, c:real; beginbeginbeginbegin

deu:=false; can:=false; vuong:=false;deu:=false; can:=false; vuong:=false;deu:=false; can:=false; vuong:=false;deu:=false; can:=false; vuong:=false; daicanh(R,a,b,c);daicanh(R,a,b,c);daicanh(R,a,b,c);daicanh(R,a,b,c); if (abs(aif (abs(aif (abs(aif (abs(a----b)<eps) and (abs(ab)<eps) and (abs(ab)<eps) and (abs(ab)<eps) and (abs(a----c)<eps) thec)<eps) thec)<eps) thec)<eps) thennnn

deu:=truedeu:=truedeu:=truedeu:=true elseelseelseelse if (abs(aif (abs(aif (abs(aif (abs(a----b)<eps) or (abs(ab)<eps) or (abs(ab)<eps) or (abs(ab)<eps) or (abs(a----c)<eps) or (abs(bc)<eps) or (abs(bc)<eps) or (abs(bc)<eps) or (abs(b----c)<eps) c)<eps) c)<eps) c)<eps) thenthenthenthen can:=true;can:=true;can:=true;can:=true;

if (abs(a*a+b*bif (abs(a*a+b*bif (abs(a*a+b*bif (abs(a*a+b*b----c*c)<eps) or (abs(a*a+c*cc*c)<eps) or (abs(a*a+c*cc*c)<eps) or (abs(a*a+c*cc*c)<eps) or (abs(a*a+c*c----b*b)<eps)b*b)<eps)b*b)<eps)b*b)<eps) or (abs(b*b+c*cor (abs(b*b+c*cor (abs(b*b+c*cor (abs(b*b+c*c----a*a)<eps) thena*a)<eps) thena*a)<eps) thena*a)<eps) then

Page 27: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] vuong:=true;vuong:=true;vuong:=true;vuong:=true;

end;end;end;end; beginbeginbeginbegin deu:=0;deu:=0;deu:=0;deu:=0;

can:=0;can:=0;can:=0;can:=0; vuong:=0;vuong:=0;vuong:=0;vuong:=0; assign(f,'tamgiac.dat');assign(f,'tamgiac.dat');assign(f,'tamgiac.dat');assign(f,'tamgiac.dat'); reset(f);reset(f);reset(f);reset(f); rrrreadln(f,n);eadln(f,n);eadln(f,n);eadln(f,n);

assign(g,'tamgiac.out');assign(g,'tamgiac.out');assign(g,'tamgiac.out');assign(g,'tamgiac.out'); rewrite(g);rewrite(g);rewrite(g);rewrite(g); for i:=1 to n dofor i:=1 to n dofor i:=1 to n dofor i:=1 to n do

beginbeginbeginbegin readln(f, T.A.x, T.A.y, T.B.x, T.B.y, T.C.x, T.C.y);readln(f, T.A.x, T.A.y, T.B.x, T.B.y, T.C.x, T.C.y);readln(f, T.A.x, T.A.y, T.B.x, T.B.y, T.C.x, T.C.y);readln(f, T.A.x, T.A.y, T.B.x, T.B.y, T.C.x, T.C.y); tinhchat(T,D,cn,v);tinhchat(T,D,cn,v);tinhchat(T,D,cn,v);tinhchat(T,D,cn,v); if d then deu:=deu+1 elseif d then deu:=deu+1 elseif d then deu:=deu+1 elseif d then deu:=deu+1 else beginbeginbeginbegin if cn then can:=can+1;if cn then can:=can+1;if cn then can:=can+1;if cn then can:=can+1; if v then vuong:=vuong+1;if v then vuong:=vuong+1;if v then vuong:=vuong+1;if v then vuong:=vuong+1; end;end;end;end; end;end;end;end; writeln(g,'co ',deu,writeln(g,'co ',deu,writeln(g,'co ',deu,writeln(g,'co ',deu,' tam giac deu');' tam giac deu');' tam giac deu');' tam giac deu'); writeln(g,'co ',can,' tam giac can');writeln(g,'co ',can,' tam giac can');writeln(g,'co ',can,' tam giac can');writeln(g,'co ',can,' tam giac can'); writeln(g,'co ',vuong,' tam giac vuong');writeln(g,'co ',vuong,' tam giac vuong');writeln(g,'co ',vuong,' tam giac vuong');writeln(g,'co ',vuong,' tam giac vuong'); close(f);close(g);close(f);close(g);close(f);close(g);close(f);close(g); end.end.end.end.

VÝ DôVÝ DôVÝ DôVÝ Dô TÖp v¨n b¶n chøa täa ®é c¸c ®Ønh cña c¸c tam gi¸cTÖp v¨n b¶n chøa täa ®é c¸c ®Ønh cña c¸c tam gi¸cTÖp v¨n b¶n chøa täa ®é c¸c ®Ønh cña c¸c tam gi¸cTÖp v¨n b¶n chøa täa ®é c¸c ®Ønh cña c¸c tam gi¸c Vµo Vµo Vµo Vµo filefilefilefile----openopenopenopen----gâgâgâgâ tamgiac.dat tamgiac.dat tamgiac.dat tamgiac.dat----nh¸y nót nh¸y nót nh¸y nót nh¸y nót open open open open råi nhËp d÷ liÖu råi nhËp d÷ liÖu råi nhËp d÷ liÖu råi nhËp d÷ liÖu nh− d−íinh− d−íinh− d−íinh− d−íi, nhÊn , nhÊn , nhÊn , nhÊn f2f2f2f2 ®Ó l−u l¹i®Ó l−u l¹i®Ó l−u l¹i®Ó l−u l¹i

Vµo Vµo Vµo Vµo filefilefilefile----openopenopenopen----gâ tamgiac.outgâ tamgiac.outgâ tamgiac.outgâ tamgiac.out----nh¸y nót open nh¸y nót open nh¸y nót open nh¸y nót open råi nhÊn råi nhÊn råi nhÊn råi nhÊn f2f2f2f2 l−u l−u l−u l−u l¹il¹il¹il¹i. NhÊn . NhÊn . NhÊn . NhÊn f6f6f6f6 chuyÓn sang cöa sæ ch−¬ng tr×nh vµ ch¹y ch−¬ng tr×nh. Ch¹y xong chuyÓn sang cöa sæ ch−¬ng tr×nh vµ ch¹y ch−¬ng tr×nh. Ch¹y xong chuyÓn sang cöa sæ ch−¬ng tr×nh vµ ch¹y ch−¬ng tr×nh. Ch¹y xong chuyÓn sang cöa sæ ch−¬ng tr×nh vµ ch¹y ch−¬ng tr×nh. Ch¹y xong nhÊn nhÊn nhÊn nhÊn yesyesyesyes, nhÊn , nhÊn , nhÊn , nhÊn f6 f6 f6 f6 cho ®Õn khi xuÊt hiÖn cöa sæ v¨n b¶ncho ®Õn khi xuÊt hiÖn cöa sæ v¨n b¶ncho ®Õn khi xuÊt hiÖn cöa sæ v¨n b¶ncho ®Õn khi xuÊt hiÖn cöa sæ v¨n b¶n tamgiac.out tamgiac.out tamgiac.out tamgiac.out xem xem xem xem kÕt qu¶.kÕt qu¶.kÕt qu¶.kÕt qu¶. TÖp v¨n b¶n chøaTÖp v¨n b¶n chøaTÖp v¨n b¶n chøaTÖp v¨n b¶n chøa kÕt qu¶ sau khi thùc hiÖn ch−¬ng tr×nh kÕt qu¶ sau khi thùc hiÖn ch−¬ng tr×nh kÕt qu¶ sau khi thùc hiÖn ch−¬ng tr×nh kÕt qu¶ sau khi thùc hiÖn ch−¬ng tr×nh

Page 28: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected]

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

1. SGK 2. Chương trình con không có tham số Procedure ve;Procedure ve;Procedure ve;Procedure ve; BeginBeginBeginBegin Writeln(‘****************’);Writeln(‘****************’);Writeln(‘****************’);Writeln(‘****************’);

Writeln(‘*I love you ok!*’);Writeln(‘*I love you ok!*’);Writeln(‘*I love you ok!*’);Writeln(‘*I love you ok!*’); Writeln(‘****************’);Writeln(‘****************’);Writeln(‘****************’);Writeln(‘****************’); End;End;End;End;

3. Chương trình con cho nhiều hơn một kết quả: Procedure hoandoi(var x, y:integer);Procedure hoandoi(var x, y:integer);Procedure hoandoi(var x, y:integer);Procedure hoandoi(var x, y:integer); Var tg:integer;Var tg:integer;Var tg:integer;Var tg:integer; BeginBeginBeginBegin Tg:=x;Tg:=x;Tg:=x;Tg:=x; X:=y;X:=y;X:=y;X:=y; Y:=tg;Y:=tg;Y:=tg;Y:=tg;

End;End;End;End;

4. program bai4;program bai4;program bai4;program bai4; uses crt;uses crt;uses crt;uses crt; var x, y:integer;var x, y:integer;var x, y:integer;var x, y:integer; function ucln(a, b:integer): integer;function ucln(a, b:integer): integer;function ucln(a, b:integer): integer;function ucln(a, b:integer): integer; var r:integer;var r:integer;var r:integer;var r:integer; beginbeginbeginbegin while b>0 dowhile b>0 dowhile b>0 dowhile b>0 do beginbeginbeginbegin r:=a mod b;r:=a mod b;r:=a mod b;r:=a mod b; a:=b;a:=b;a:=b;a:=b; b:=r;b:=r;b:=r;b:=r; end;end;end;end; ucln:=a;ucln:=a;ucln:=a;ucln:=a; end;end;end;end; function bcnn(a, b:integer): integer;function bcnn(a, b:integer): integer;function bcnn(a, b:integer): integer;function bcnn(a, b:integer): integer; beginbeginbeginbegin

Page 29: Giải bài tập Tin học 11 SGK

Great by: Nguyễn Trọng Hoàng Email: [email protected] bcnn:=a*b div ucln(a,b);bcnn:=a*b div ucln(a,b);bcnn:=a*b div ucln(a,b);bcnn:=a*b div ucln(a,b);

enenenend;d;d;d; beginbeginbeginbegin 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('Boi chung nho nhat: ',bcnn(x,y));write('Boi chung nho nhat: ',bcnn(x,y));write('Boi chung nho nhat: ',bcnn(x,y));write('Boi chung nho nhat: ',bcnn(x,y)); readlnreadlnreadlnreadln end.end.end.end.

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