Ko`p o`lchamli massivlar va ular ustida amallar
Bir o`lchamli massivlarning hadlari skalyar miqdorlar bo`lgan edi. Umumiy holda esa,
massiv hadlari o`z navbatida yana massivlar bo`lishi mumkin, agar bu massivlar skalyar
miqdorlar bo`lsa, natijada ikki o`lchamli massivlarni hosil qilamiz. Ikki o`lchamli massivlarga
misol sifatida matеmatika kursidagi matrisalarni kеltirish mumkin. Agar bir o`lchamli
massivning hadlari o`z navbatida matrisalar bo`lsa natijada uch o`lchovli massivlar hosil qilinadi
va h.k.
Ikki o`lchamli massiv tipini ko`rsatish quyidagicha bajariladi:
array
[]
of array
[]
of
;
Ikki o`lchamli massivlarning tiplarini bir nеcha xil yo`lda aniqlashni quyidagi misol ustida
ko`rib chiqaylik (A matrisa 10 ta satr va 20 ta ustundan iborat bo`lib, uning hadlari haqiyqiy
tipga tеgishli bo`lsin):
1. var
A: array [1..10] of array [1..20] of real;
2. type matr q array [1..10] of array [1..20] of real;
var
A: matr;
3. type gran1 q 1..10; gran2 q 1..20;
matr q array [gran1, gran2] of real;
var
A: matr;
4. var
A: array [1..10, 1..20] of real;
Yana shuni ham aytish mumkinki, ikki o`lchamli massiv indеkslarining tiplari turli xil ham
bo`lishi mumkin. Bu holni quyidagi misol ustida ko`rib chiqaylik:
Program L1;
const n = 24;
type
hafcun = (dush, sesh, chor, pay, jum, shan, yaksh);
Ishkun = dush..jum;
detson = array [1..n] of char;
var
A: array [boolean] of array [1..n] of char;
B: detson;
S: array [1..365] of detson;
Ikki o`lchamli massivlar ustidagi bir nеchta tugallangan programmalar bilan tanishib
chiqaylik.
1. Matrisalarni qo`shish.
Program L2;
const n = 3; m = 4;
{ n - matrisa satrlari soni,
m - ustunlar soni}
var
i, j: integer;
A, B, C: array [1..n,1..m] of real;
begin {A, V
matrisa hadlarini kiritish}
for i : = 1 to n do
for j: =1 to m do
readln (A[i,j], B[i,j]);
for i : = 1 to n do
for j: = 1 to m do
begin
C[i,j] := A[i,j] + B[i,j];
writeln (C[i,j])
end
end.
2. Matrisani vеktorga ko`paytirish.
Program L3;
const n =3; m = 4;
type matr = array [1..n, 1..m] of real;
vect = array [1..m] of real;
var
i, j: byte;
A: matr;
B, C: vect;
begin
writeln
(‗A matrisa hadlarini kiriting‘);
for i:q1 to n do
for j:q1 to m do
readln (A[i,j]);
writeln
(‗B vеktor hadlarini kiriting‘);
for i:q1 to n do readln (B[i]);
for i:=1 to n do
begin
C[i]:0;
for j:=1 to m do
C[i]:= C[i] + A[i,j] * B[j];
writeln (C[i]);
end;
end.
3. Matrisa hadlarining eng kattasini topish va uning joylashgan joyini aniqlash.
Program L4;
const n=3; m=4;
var
A: array [1..n, 1..m] of real;
R: real;
i, j: byte; K, L: byte;
begin
{A matrisa hadlarini kiritish}
for i: =1 to n do
for j: =1 to m do
readln (A[i,j]);
R:= A[1,1]; L:= 1; K:= 1;
for i: =1 to n do
for j: =1 to m do
begin
if R< A[i,j] then
begin
R:=A[i,j];
L:= i; K: =j;
end;
end;
writeln
(‗max A=‘, R);
writeln
(‗satr =‘,L,‘ustun =‘,K);
end.
Do'stlaringiz bilan baham: |