Array
ARRAY adalah adalah Tipe
terstruktur yang terdiri dari sejumlah komponen-komponen yang mempunyai tipe yang sama. Suatu Array
mempunyai jumlah komponen yang banyaknya tetap. Banyaknya komponen dalam suatu
larik ditunjukan oleh suatu indek untuk membedakan variabel yang satu dengan
variabel yang lainnya.
Array Satu Dimensi
Bentuk Umum
pendeklarasian array :
Keterangan :
- Type Data : Untuk menyatakan type data yang digunakan.
- Ukuran : Untuk menyatakan jumlah maksimum elemen array.
float Nil_Akhir[5];
Suatu array dapat digambarkan sebagai kotak panjang
yang berisi kotakkotak kecil didalam kotak panjang tersebut.
Subscript atau Index array pada C++, selalu dimulai dari Nol ( 0 )
Suatu array, dapat diakses dengan menggunakan
subscript atau indexnya: Bentuk umum
pengaksesan dengan bentuk :
Contoh : Nilai_Akhir[4];
Nilai_Akhir[6];
Nilai_Akhir[2];
Inisialisasi adalah
memberikan nilai awal terhadap suatu variabel. Bentuk pendefinisian suatu array dapat dilihat dari
contoh berikut :
Tipe_data nama_array[jml_elemen] = { nilai array };
Coding Array Satu Dimensi
/* ----------------------------- */
/* Inisialisasi Array Dimensi 1 */
/* ----------------------------- */
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
void main()
{
int nilai[5] = {3, 7, 5, 6, 2};
int i;
clrscr();
for(i=0; i<5; i++)
{
cout<<"Nilai Array Index ke - "<<i<<" = ";
cout<<nilai[i]<<endl;
}
getch();
}
Hasil Output Array Satu Dimensi
Array Dua Dimensi
Terima Kasih.Semoga Bermaanfaat
Daftar Pustaka
Pemograman C++ Dengan Borland C++ 5.02
/* ----------------------------- */
/* Inisialisasi Array Dimensi 1 */
/* ----------------------------- */
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
void main()
{
int nilai[5] = {3, 7, 5, 6, 2};
int i;
clrscr();
for(i=0; i<5; i++)
{
cout<<"Nilai Array Index ke - "<<i<<" = ";
cout<<nilai[i]<<endl;
}
getch();
}
Hasil Output Array Satu Dimensi
Array Dua Dimensi
Array dimensi dua
tersusun dalam bentuk baris dan kolom, dimana indeks pertama menunjukan baris
dan indeks kedua menunjukan kolom. Array dimensi dua dapat digunakan seperti
pendatan penjualan, pendataan nilai dan lain sebagainya.
Bentuk Umum
pendeklarasian array :
Keterangan :
- Type Data : Untuk menyatakan type data yang digunakan.
- Index-1 : Untuk menyatakan jumlah baris
- Index-2 : Untuk menyatakan jumlah kolom
Contoh : data_jual[2][2];
data_jual[1][2];
Inisialisasi adalah
memberikan nilai awal terhadap suatu variabel. Bentuk pendefinisian suatu array dapat dilihat dari
contoh berikut :
Tipe_data nama_array[jml_elemen] = { nilai
array };
Contoh
int data[2][5] = { {5, 7, 2, 10, 12},{24, 21, 16,
27, 17} };
Coding Array Dua Dimensi
/* ----------------------------- */
/* Inisialisasi Array Dimensi 2 */
/* ----------------------------- */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void main()
{
int i, j;
int data[2][5] = {{2, 3, 4, 5, 2},{4, 2, 6, 2, 7}};
clrscr();
for(i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
cout<<data[i][j];
cout<<" ";
}
cout<<endl;
}
getch();
}
Hasil Output Coding Array 2 Dimensi
Coding Array Dua Dimensi
/* ----------------------------- */
/* Inisialisasi Array Dimensi 2 */
/* ----------------------------- */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void main()
{
int i, j;
int data[2][5] = {{2, 3, 4, 5, 2},{4, 2, 6, 2, 7}};
clrscr();
for(i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
cout<<data[i][j];
cout<<" ";
}
cout<<endl;
}
getch();
}
Hasil Output Coding Array 2 Dimensi
Terima Kasih.Semoga Bermaanfaat
Daftar Pustaka
Pemograman C++ Dengan Borland C++ 5.02
Did you hear there's a 12 word phrase you can speak to your man... that will trigger intense feelings of love and instinctual appeal to you buried within his chest?
ReplyDeleteThat's because hidden in these 12 words is a "secret signal" that fuels a man's impulse to love, treasure and protect you with his entire heart...
12 Words Who Fuel A Man's Love Response
This impulse is so built-in to a man's mind that it will drive him to try better than ever before to make your relationship the best part of both of your lives.
Matter of fact, triggering this mighty impulse is absolutely mandatory to achieving the best possible relationship with your man that the second you send your man one of these "Secret Signals"...
...You will immediately notice him open his heart and soul to you in such a way he's never experienced before and he will identify you as the one and only woman in the galaxy who has ever truly attracted him.