Program C++ Array – Satu dan Dua dimensi

April 22, 2012 at 10:05 am Leave a comment

Contoh Program Array 1 Dimensi


#include<iostream.h>
#include<conio.h>
main()
{
int a[5]={10,15,20,25,30};
int b[5]={10,20};
int c[5]={15,0,30};
int j;

// Menampilkan nilai dari element array
cout<<endl;
for(j=0;j<5;j++)
{
cout<<"A ["<<j<<"] = "<<a[j]<<" , B ["<<j<<"] = "<<b[j]<<" , C ["<<j<<"] = "<<c[j]<<endl;
}
getch();
}

Program Array 2 Dimensi

//array dua dimensi
#include<iostream.h>
#include<conio.h>
main()
{
int matrix[3][3];
int i,j;

for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<"Masukkan angka pada baris ke "<<i<<" kolom ke "<<j<<" : ";
cin>>matrix[i][j];
}
cout<<endl;
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
getch();
}

Entry filed under: Pemograman C++. Tags: .

Looping dalam C++ Representasi Data & Format Data Komputer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


JAM

Admin

Categories

Recent Posts

DATE

Blog Stats

  • 3,258 hits

%d bloggers like this: