|
Write (Size:3,’ta massiv elementini kiriting’)
|
bet | 3/3 | Sana | 08.06.2024 | Hajmi | 168,43 Kb. | | #261615 |
Bog'liq 19 Amaliy mashg’ulot Write (Size:3,’ta massiv elementini kiriting’);
For k:=1 to Size Do Read(a[k]);
Writeln (‘Тartiblatirish’);
For i:=1 to Size-1 Do
Begin
For k:=1 to Size-1 Do
Begin
If a[k]>a[kq1] then
Begin
buf:=a[k]; a[k]:=a[kq1]; a[kq1]:=buf;
End;
End;
For k:=1 to Size Do Write (a[k],’ ‘);
Writeln;
End;
Writeln(‘Massiv tartiblashtirildi.’);
End.
Dastur natijasi:
Massivni puzirek usulida tartiblashtirish
5 ta massiv elementini kiriting
3 2 4 1 5
Тartiblashtirish
2 3 4 1 5
2 3 1 4 5
2 1 3 4 5
1 2 3 4 5
Massiv tartiblashtirildi.
Massivda eng kichik yoki eng katta elementni izlash algoritmi ma’lumki birinchi element eng kichik (katta)
Program MinMax;
Var i,min: Integer;
a: Array[1..10] of Integer;
Begin
Dinamik massiv
Dinamik massiv ta’riflanganda uning uzunligini ko’rsatish shart emas.
Massiv uzunligini o’rnatish uchun SetLength funksiyasidan foydalanish mumkin.
Uning ikki parametri mavjud:
1. Dinamik massiv tipidagi o’zgaruvchi.
2. Massiv uzunligi.
High(r) funksiyasi massiv elementlari sonini qaytaradi.
Misol:
r:array of integer;
i:Integer;
begin
SetLength(r,10);
for i:=0 to High(r)-1 do
begin
r[i]:=i*i;
writeln (IntToStr(i)q' kvadrati ='qIntToStr(r[i]));
end;
IntToStr funksiyasi sonni satrga aylantiradi.
Nazorat savollari
1. Massivlar haqida ma’lumot bering.
2. Massivlarning qo’llanilish sohalari
3. Massivlarning turlarini sanang.
|
| |