• 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
  • Writeln(‘Massiv tartiblashtirildi.’); End.
  • Program MinMax; Var i,min: Integer; a: Array[1..10] of Integer; Begin Writeln (‘Massivdan eng kichik elementni izlash’);
  • Writeln(‘Izlanayotgan eng kichik element:’,a[min]); Writeln(‘Element nomeri’,min); End. Dinamik massiv
  • O’qitish materiallari




    Download 8,44 Mb.
    bet95/127
    Sana12.01.2024
    Hajmi8,44 Mb.
    #135555
    1   ...   91   92   93   94   95   96   97   98   ...   127
    Bog'liq
    toplam 2 kurs

    Program Sort;
    Const Size=5;
    Var i,j,min,k,buf: Integer;
    a: Array[1..Size] of Integer;
    Begin
    Writeln (‘Massivni puzirek(kupikcha) usulida tartiblashtirish’);
    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) deb olinib keyin boshqa elementlar bilan ketma-ket solishtirilib chiqiladi. Solishtirilish oxirgi elementgacha bajariladi.
    Quyida bu algoritm dastursi keltirilgan:
    Program MinMax;
    Var i,min: Integer;
    a: Array[1..10] of Integer;
    Begin
    Writeln (‘Massivdan eng kichik elementni izlash’);
    Write (’ 10-ta massiv elementini kiriting’);
    For i:=1 to 10 Do Read(a[i]);
    min:=1;
    For i:=2 to 10 Do
    If a[i]
    Writeln(‘Izlanayotgan eng kichik element:’,a[min]);
    Writeln(‘Element nomeri’,min);
    End.
    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:

    Download 8,44 Mb.
    1   ...   91   92   93   94   95   96   97   98   ...   127




    Download 8,44 Mb.