Array 2 dimensi

18 Apr

Two-dimensional array is an array that has two subscripts of rows and columns.
The general form of two-dimensional array declaration:
Tipe_data nama_array [banyak_baris] [banyak_kolom];

Examples of programs:
program array multi dimensi*/
# include

main()
{
int i,j;
int x[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};

for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
printf(“%6d”,x[i][j]);
printf(“\n”);
}
printf(“\n”);
}

/* program array multi dimensi*/
#include

main()
{

int x[3][4],i,j;

for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
{
printf(“input data matrik [%i][%i]:”,i,j);
scanf(“%i”,&x[i][j]);
}
}

printf(“\nOutput data matrik\n”);

for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
printf(“%6i”,x[i][j]);
printf(“\n”);
}
}

#include
main()
{
int A[3][2], B[3][2],C[3][2], i, j;
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf(“input data matrik A[%i][%i] :”,i,j);
scanf(“%i”,&A[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf(“input data matrik B[%i][%i] :”,i,j);
scanf(“%i”,&B[i][j]);
}
}

for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
printf(“\n matrik penjumlahan A+B\n”);
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
printf(“%6i”,C[i][j]);
printf(“\n\n”);
}

This is an example program to input data / values ​​and find the average by using arrays.
#include
#include
main()
{
int i,data;
char nama[30];
float nilai[100];
float rata;

printf(“Bayaknya data : “);
scanf(“%d”,&data);

for(i=0; i<data; i++)
{
printf(“Data mahasiswa ke-[%d]\n”,i+1);
printf(“Nama = “);
scanf(“%s”,&nama);
printf(“Nilai = “);
scanf(“%f”,&nilai[i]);
}
{
float jum=0;
for(i=0; i<data; i++)
jum+=nilai[i];
rata=jum/data;
}
printf(“\n”);
printf(“Daftar Nilai Mahasiswa\n”);
printf(“================================\n”);
printf(“Nama mahasiswa Nilai \n”);
printf(“================================\n”);
for(i=0; i<data; i++)
{
printf(“\n%s “,nama);
printf(“%1.f”,nilai[i]);
}
printf(“\n================================\n”);
printf(“rata-rata adalah = %.1f”,rata);
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: