program pemangkatan matrix NAMA : vasko edo gultom NIM : 071402009 */


/*
program pemangkatan matrix
NAMA : vasko edo gultom
NIM : 071402009
*/

#include

int main()
{
int a, b, k, n, x, y;
int matrixA[100][100], matrixB[100][100], hasil[100][100];

printf(“Masukkan ordo matrix (1 s/d 100): “);
scanf(“%d”, &n);

// Memasukkan elemen matrix
for(a = 0; a < n; a ++)
for(b = 0; b < n; b++)
{
printf("Nilai matrix baris %d, kolom %d: ", a+1, b+1);
scanf("%d", &matrixA[a][b]);
}
printf("\n");

// Menampilkan elemen matrix
for(a = 0; a < n; a++)
{
for(b = 0; b < n; b++)
printf("%10d", matrixA[a][b]);
printf("\n");
}
printf("\n");

printf("Masukkan pemangkatan matrix: ");
scanf("%d", &x);
printf("\n");

for(a = 0; a < n; a++)
for(b = 0; b < n; b ++)
for(k = 0; k < n; k++)
{
matrixB[a][b] = matrixA[a][b];
hasil[a][b]=0;
}

// Memangkatkan matrix
for(y = 1; y < x; y++)
{
for(a = 0; a < n; a++)
for(b = 0; b < n; b ++)
{
for(k = 0; k < n; k++)
hasil[a][b] += matrixA[a][k] * matrixB[k][b];
}

for(a = 0; a < n; a++)
for(b = 0; b< n; b++)
{
matrixB[a][b] = hasil[a][b];
hasil[a][b] = 0;
}
}

// Menampilkan elemen matrix
for(a = 0; a < n; a++)
{
for(b = 0; b < n; b++)
printf("%10d", matrixB[a][b]);
printf("\n");
}
printf("\n");

return 0;
}

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

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