1 / 10

Array Dimensi

Array Dimensi. Sri marini , ST. Mengingat Kembali. Array adalah tipe terstruktur yang terdiri dari sejumlah komponen-komponen yang mempunyai tipe yang sama . Contoh : Var X : Array[1..100] of Integer ……. X[1] := 25; X[2] := 75; …..

ilana
Download Presentation

Array Dimensi

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Array Dimensi Sri marini, ST

  2. Mengingat Kembali • Array adalahtipeterstruktur yang terdiridarisejumlahkomponen-komponen yang mempunyaitipe yang sama. • Contoh : Var X : Array[1..100] of Integer ……. X[1] := 25; X[2] := 75; ….. writeLn (X[1]); {untukmenampilkan Array X pertama}

  3. Array Dimensi Banyak • Array dapat juga berdimensi lebih dari satu yang disebut array dimensi banyak (multidimensi array). • Array Berdimensi Dua (Two Dimensional Array) • Array Berdimensi Tiga (Three Dimensional Array) • Dst…

  4. Array Dimensi Dua • Array DimensiDuamewakilisuatubentuktabelataumatrik, yaituindeks yang pertamadapatmenunjukkanbarisdanindekskeduadapatmenunjukkankolomdaritabelataumatrik. nama_array = array[tipe_indeks1] of array [tipe_indeks2] of tipe_data; atau, nama_array = array[tipe_indeks1,tipe_indeks2] of tipe_data;

  5. Contoh Uses wincrt; Var Tabel : array[1..3,1..2] of byte; I,J : byte; Begin Tabel[1,1] := 5; Tabel[1,2] := 25; Tabel[2,1] := 200; Tabel[2,2] := 22; Tabel[3,1] := 75; Tabel[3,2]:= 50; For I := 1 to 3 do Begin For J := 1 to 2 do Begin write (Tabel[I,J]:5); End; writeLn End; End. Menampilkan nilai array 5

  6. Lanjutan… Tabel[1,1] := 5; Tabel[1,2] := 25; Tabel[2,1] := 200; Tabel[2,2] := 22; Tabel[3,1] := 75; Tabel[3,2]:= 50; • Untukmengisinilaibisalangsungpada program sepertidiatasataubisadenganReadLn; For I := 1 to 3 do Begin For J := 1 to 2 do Begin write ('MasukanNilaiTabel[',I,',',J,'] = '); ReadlN (Tabel[I,J]); End; End; Perhatikan penggunaan koma Utk memisahkan nilai variabel (I dan J) Dan tampilan karakter (masukan nilai tabel)

  7. Deklarasi Array Dimensi Dua • Seperticontohsebelumnyadeklarasi array ditulis : Var Tabel : array[1..3,1..2] of byte; • Bisajugaditulisseperti : Type X = array[1..3,1..2] of byte; Var Tabel : X; • Atau; Type Baris = 1..3; Kolom = 1..2; X = array[Baris,Kolom] of Byte; Var Tabel : X;

  8. Parameter Larik • Larik dapat digunakan sebagai parameter yang dikirimkan baik secara nilai(by value) atau secara acuan (by reference) ke prosedur atau fungsi. • Prosedur yang menggunakan parameter barupa larik harus dideklarasikan di dalam judul prosedur yang menyebutkan parameternya bertipe larik.

  9. Contoh Uses wincrt; Type Larik = array[1..50,1..50] of Real; Var I,J,K , N: byte; X : Larik; Procedure Invers(Var X : Larik; N : byte); Var Pv, A : real; Begin For I := 1 to N do Begin PV := X[I,I]; X[I,I] := 1; For J := 1 to N do X[I,J] := X[I,J]/ PV; For K := 1 to N do Begin If K <> I Then Begin A := X[K,I] X[K,I] := 0; For J:= 1 to N do X[K,J] := X[K,J]-A*X[I,J]; End; End; End; End;

  10. Lanjutan Contoh… {program utama} Begin Clrscr; Write ('Ordedarimatrik ? '); Readln(N); WriteLn; {memasukkan data} For I := 1 to N do Begin For J := 1 to N do Begin Write( 'Nilai [', I, ' , ' ,J, '] = '); ReadLn (X[I,J]); End; WriteLn; End; {mencetaknilaimatrikasli} Clrscr; writeLn ('MatrikAwal'); For I := 1 to N do Begin For J := 1 to N do Write ( X[I,J]:10); WriteLn; End; {menghitunginversmatrik} Invers(X,N); writeLn; {mencetakinvermatrik} WriteLn ('MatriksInvers'); For I := 1 to N do Begin For J := 1 to N do Write ( X[I,J]:10); WriteLn; End; End.

More Related