Ko’p o’lchamli massivlar 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 matematika kursidagi matrisalarni keltirish 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:
Ikki o’lchamli massivlar tiplarini aniqlashni bir necha xil yo’lda quyidagi misol ustida ko’rib chiqaylik: (10 ta satr va 20 ta ustundan iborat matrisa tipini aniqlash, massiv hadlari real tipida bo’lsin)
1. array [1..10] of array [1..20] of real;
2. var A: array [1..10] of array [1..20] of real;
3. type matr = array [1..10] of array [1..20] of real;
Var A: matr;
4. type gran1 = 1..10; gran2 = 1..20; matr = array [gran1, gran2] of real; var A: matr;
5. var A: array [1..10, 1..20] of real;
Yana shuni aytish mumkinki, ikki o’lchamli massiv indekslarining tiplari turli xil ham bo’lishi mumkin. Bu holni quyidagi misol ustida ko’rib chiqaylik:
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 ustida bir nechta tugallangan programmalar bilan tanishib chiqaylik.
1. Matrisalarni qo’shish.
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 xadlarini kiritish}
for j : = 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 vektorga ko’paytirish.
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 xadlarini kiriting’);
for i:=1 to n do for j:=1 to m do readln (A[i,j]);
writeln (‘B vektor xadlarini kiriting’); for i:=1 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 kattasi (kichigi)ni topish va uning joylashgan joyini aniqlash.
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: |