Contoh Program C++ Array - Satu dan Dua dimensi

Posted by Lego Share on 08:47 AM, 30-Oct-12

Under: C++

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 dua 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[j];
}
cout<<endl;
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<matrix
[j]<<" ";
}
cout<<endl;
}
getch();
}

Share on Facebook Share on Twitter

Comments

2 responses to "Contoh Program C++ Array - Satu dan Dua dimensi"

andre on 09:27 AM, 30-Oct-12

thanks ya gan smile

andre on 09:27 AM, 30-Oct-12

thanks ya gan smile

Subscribe to comments feed: [RSS] [Atom]

New Comment

[Sign In]
Name:

Email:

Comment:
(Some BBCode tags are allowed)

Security Code:
Enable Images