Lý thuyết và bài tập Pascal
Trang 4writein(Khong co hop so nao’); readin; end {Bai 3.11} uses cit; const nmax = 32000, type mang = array [1 nmax] of Integer, var ni: integer; a:mang; ketthuc : boolean; {: text, Procedure inketqua(k:integer); var j: integer, begin for j:=1 to k do write(f,alj}:5); writeln(f); end; Procedure sinhmoi(K:integer);
{Xay dung mot tong khac co thu tu lon hon thoa man : cac so hang cua tong tang dan}
Trang 7+ mang[4], - mang[4]; * mang[4]; 4:t:=t/ mang[4];, end; case d of 1:t:=t + mang[5]; 2: †- mang[5]; 3: t:=t* mang[5]; 4: †/ mang[5]; end; ifn=tthen begin dien := true; writeln(n = ', '(((1' op[a], '2}, op[b], 4), op[c] '5)', op[d], '6); end; end;
if not dien then
writeln(‘Khong the dien’); readin; end {Bai 3.13} uses crt; const nmax = 50; type ma_tran = array [1 nmax, 1 nmax] of integer; var a,b : ma_tran; n,i,j : byte;
_ Procedure Nhap_mt(var a : ma_tran;var n : byte);
var i,j : byte; x,y : integer;
begin
_ fepeat
Trang 9writeln; for i:=1 ton do begin for j:=1 to n do 'write(a[ij]:8); 'writeln; end; end; BEGIN Nhap_mt(a,n); writeln(‘Nhap chi so dong va chỉ so cot can bo ); 'write('Dong : ');readin(i); write('Cot : ');readIn(); Matrancon(i,j,n,a,b); In_matran(n-1,b); readin; END (Bai 3.14} uses crt; const nmax = 50; type ma_tran = array [1 nmax,1 nmax] of integer; var a:ma_tran; n,ij,k : byte; tg : integer; f,f1,f2,f3 : boolean;
Procedure Nhap_mt(var a : ma_tran;var n : byte);
Trang 10read(n); until (n>0) and (n<51); :=1 to n do {co the nhap ket qua: read(a[lj): Ì a[ji:=2-a[ijl: end; end; end; Procedure In_matran(n:byte;a : ma_tran); var i,j:byte; begin 'writeln; for ï:=1 ton do begin for j:=1 to n do write(alij]:8); 'writeln; end; end, Begin Nhap_mt(a,n); in_matran(n,a); f ¡f2:=false;f3:=false, for i:=1 ton do begin tg:=0;
Ie;{gia su doi i khong thua} ;=0;{k la so tran thang cua doi i}
Trang 11for j:=1 ton do begin tg:=tg+alij]; ïf (alij]E0) and (<>j) then f:=false;(doi ¡ da thua}
Trang 13eit; end; writeln(Day sau khi xoa cac so 0:'); for ï := 1 to m do writeln(b[i]); {xoa cac so < 0} b:= a; { sao luu mầng a } m:=n; i=; while i <= m do begin if b{i] < 0 then begin for j:=itom-1do bị] := b[j+1]; m:=m-1, end; writeln(‘Day sau khi xoa cac so < 0:); for ¡ :=,1 to m do writeln(b[i]);
Trang 15begin write (‘af'i,',')j,] readln(a[i,j]); end; for i= 1 ton do begin min[i= a[i,1]; for j;= 1 to m do if min[i| > a[ij] then min[i| := a[ij]; end; for ï:= 1 ton do for j= 1 tom do if a[ij] = mini] then bfi,] for j:= 1 to m do begin max[j] := a[1,]] for tondo if max[j] < afi,j] then max{[i] := a[i,j]; end; for j:= 1 tomdo for i:= 1 tondo
if a[i,j] = max{j] then cfi,j) :
Trang 16writeln; for i:= 1 ton do begin writeln; for j= 1 tom do write(’', c[i,j),"); end; writeln; for i= 1 ton do for j:= 1 to m do if (cfij] = 1) and (bfi,j] = 1) then begin
writeln (' Diem yen ngua cua ma tran la : a['j,1j,]);
writeln (' Gia tri tai diem yen ngua la : ‘,ali,j]); thay := true; end; if thay = false then write (‘ MA TRAN KO CO DIEM YEN NGUA'’); readin; end {Bai 3.17} Uses crt, const nmax = 50;
Type matran = array[1 nmax,1 nmax+1] of real; mang = array [1 nmax+1] of real,
Var
a: matran; nị : byte; x: mang;
Procedure Nhapmt(var a : matran;var n : byte);
var i,j: byte; xy : integer; begin
repeat
Trang 17write(‘nhap so an cua phuong trinh (<=50) : '); read(n); until (n>0) and (n<51); 'writelnNhap cac phan tu cua ma tran he so (du) :'); y:=whereY; for Ï;=1 to n do begin GotoXY(x,y); read(a[ij]); end; end; end;
function Khuheso(var a : matran;n : byte) : boolean;
Var i,j,k : byte; max,tg : real; am :boolean; Begin for i:=1 to n do begin
{chon he so max cua cot ¡
trong cac dong can khu : tu ¡ den n}
ma: :
for k:=i to n do
Trang 18begin {phuong trinh vo no hoac vo so no} khuheso:=false; exit; { thoat } end; {doi dong j cho dong i} for k:=i to n+1 do end; {chia dong i cho max : } if am then max:=-max;
for k:=i to n+1 do a[i,k]:=ali,k]/max;
for j:=i+1 ton do begin tg:=a[ii]: for k:=i to n+1 do i, afj,k]-tg*ali,k]; end; khuheso:=true' end;
Trang 19BEGIN
nhapmt(a,n);
if not khuheso(a,n) then
Writeln(Phuong trinh co vo nghiem.)) else begin
timnghiem(a,n,x);
'Writeln(Bo nghiem cua phuong trình la : ');
for i:=1 to n do writeln(x[i]:8:8); end;
write(‘an Esc de thoa);
Trang 20readIn(b[iij]): end;
writeln (‘MA TRAN A’), for i:= 1 tondo begin for tomdo write ("', ail" )i writeln, end; writeln ( ' MA TRAN B); for i:= 1 tondo begin for j:= 1 tom do write (*', bli)" )s writeln; end; for i;= 1ton do for tom do
fi) = ali) + bE)
Trang 23writeln (" MA TRAN A’); for i:= 1 ton do begin for j:= 1 to m do write (*', afi,j]," ); writeln; end; writen (‘ MA TRAN B’); for i:= 1 tom do begin for j:= 1 to p do write ("', bfi,j],"); 'writeln; end; 1tondo for j:= † to p do for k= 1t†om do clij] := cfii]+afi,K]"b[kij]; 'writeln( ' MA TRAN A*B), for ï:= 1 tondo begin for j:= 1 to m do write ("', c[j]," ); 'writeln;, end; readin; End {Bai 3.22} uses crt; const nmax = 20; type
matran = array [1 nmax,1 nmax] of real; var a,b : matran; n : byte;
.chiso : array[1 nmax] of byte;
Trang 24
Procedure Nhap_mt(var a : matran;var n : byte); var ij: byte; xy : integer; begin write(nhap n = ');read(n); 'writeln(Nhap cac phan tu cua ma tran :); y:=whereY; for i:=1 ton do begin :=2;inc(y), for j}=1 to n do begin X:=x+5; GotoXY(x,y); read(ali,j)); end; end; end;
function Dinhthuc(n:byte;a : matran) : real;
Var ij.k : byte; max,tg,Dinh_thuc : real;
am : boolean;
Begin
Dinh_thuc:=1;
{Buoc i khu he so o cot i}
for i:=1 ton do
begin
{chon he so max cua cot i
Trang 25if a[ki]<0 then am:=true else am:=false; end;
if max = 0 then