Uncategorized

Algoritma dan Strukdat (Materi 3: Array)


Berikut ini adalah contoh source code membuat inputan array s.d. transpose array (Matriks)

#include <stdio.h>

void main()
{
	//Deklarasi Matriks
	int matriks[3][3];

	//inputan matriks
	printf("\n\nInputkan Matriks: \n");
	for(int baris=0;baris<3;baris++)
	{
		for (int kolom=0;kolom<3;kolom++)
		{
			printf("Inputkan Matriks [%d][%d] : ",baris,kolom);
			scanf("%d",&matriks[baris][kolom]);
		}
		printf("\n");
	}

	//Menampilkan nilai matriks
	printf("\n\nNilai Matriks: \n");
	for(int baris1=0;baris1<3;baris1++)
	{
		for (int kolom1=0;kolom1<3;kolom1++)
		{
			printf("\nNilai Matriks [%d][%d] : %d",baris1,kolom1,matriks[baris1][kolom1]);

		}
		printf("\n");
	}

	//Menampilkan dalam format matriks
	printf("\n\nBentuk Matriks: \n");
	for(int baris2=0;baris2<3;baris2++)
	{
		for (int kolom2=0;kolom2<3;kolom2++)
		{
			printf("%d\t",matriks[baris2][kolom2]);

		}
		printf("\n");
	}

	//Menampilkan dalam TRANSPOSES format matriks
	printf("\n\nBentuk Transpose Matriks: \n");
	for(int baris3=0;baris3<3;baris3++)
	{
		for (int kolom3=0;kolom3<3;kolom3++)
		{
			printf("%d\t",matriks[kolom3][baris3]);

		}
		printf("\n");
	}

}
Advertisements

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