x: array [1..n] of real; S: real; begin for i: =1 to n do readln (x[i]); { massiv hadlarini kiritish} S: =0; for i: =1 to n do S: =S+x[i]; writeln (‘natijaq’, S) end. 2. Bir o’lchamli, n ta hadli (n=30) massiv hadlarining eng kattasini topish va uning joylashgan joyini aniqlash.
Program L2; const n=30; type gran = 1..30; vector = array [gran] of real; var x: vector; S: real; i, k: integer; begin writeln (‘ x - massivi hadlarini kiriting’);
for i: =1 to n do readln (x[i]); S: =x[1]; k: =1; for i: =2 to n do if x[i] > S then begin S: =x[i]; k: =i end; writeln (‘x massivininig eng katta hadi’);
writeln (S); writeln (‘max(x) ning o’rni’, k) end.
3. n ta hadli (n = 15) vektorlarning skalyar ko’paytmasini aniqlash.
Program L3; const n=15; type gran = 1..n; mas = array [gran] of real; var i: byte; S: real; x, y: mas; begin writeln (‘x va u massiv hadlarini kiriting’);
for i: =1 to n do readln (x[i]); for i: =1 to n do readln (y[i]); S: =0; for i:=1 to n do S:= S + x[i] * y[i]; writeln (‘natija’,S) end.
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 matri salarni keltirish mumkin. Agar bir o’lchamli massivning hadlari o’z navbatida matri salar 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 necha xil yo’lda aniqlashni quyidagi misol ustida ko’rib chiqaylik (A matri sa 10 ta satr va 20 ta ustundan iborat bo’lib, uning xadlari haqiqiy tipga tegishli bo’lsin):
1. var A: array [1..10] of array [1..20] of real; 2. type matr = array [1..10] of array [1..20] of real; var A: matr; 3. type gran1 = 1..10; gran2 = 1..20; matr = 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 indekslarining 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 nechta tugallangan programmalar bilan tanishib chiqaylik.
1. Matri salarni qo’shish.
Program L2; const n = 3; m = 4;