Program ini merupakan request seseorang yaitu program perkalian n transpose matriks 2x2
source codenya :
# include <stdio.h>
# include <conio.h>
void input_matriks(int matriks_a[][2], int matriks_b[][2])
{
int i,j;
printf("Masukan Elemen Matriks A (Sesuai Baris) : \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
scanf("%d", &matriks_a[i][j]);
}
printf("\nMasukan Elemen Matriks B (Sesuai Baris) : \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
scanf("%d", &matriks_b[i][j]);
}
}
void kali_matriks(int matriks_a[][2], int matriks_b[][2], int matriks_c[][2])
{
int i,j,k;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
matriks_c[i][j] = 0;
for (k = 0; k < 2; k++)
matriks_c[i][j] += matriks_a[i][k] * matriks_b[k][j];
}
}
}
void transpos_matriks(int matriks_c[][2], int trans[][2])
{
int i,j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
trans[j][i] = matriks_c[i][j];
}
int main()
{
int matriks_a[2][2], matriks_b[2][2], matriks_c[2][2], trans[2][2];
int i,j;
printf("Program Perkalian dan Transpose Matriks (2*2) \n\n");
input_matriks(matriks_a, matriks_b);
kali_matriks(matriks_a, matriks_b, matriks_c);
transpos_matriks(matriks_c, trans);
printf("\nHasil Perkalian Matrik A x B = (Matrik C) : \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
printf("%3d", matriks_c[i][j]);
printf("\n");
}
printf("\nHasil Transpose matrik C adalah: \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
printf("%3d", trans[i][j]);
printf("\n");
}
getch();
return 0;
}
source codenya :
# include <stdio.h>
# include <conio.h>
void input_matriks(int matriks_a[][2], int matriks_b[][2])
{
int i,j;
printf("Masukan Elemen Matriks A (Sesuai Baris) : \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
scanf("%d", &matriks_a[i][j]);
}
printf("\nMasukan Elemen Matriks B (Sesuai Baris) : \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
scanf("%d", &matriks_b[i][j]);
}
}
void kali_matriks(int matriks_a[][2], int matriks_b[][2], int matriks_c[][2])
{
int i,j,k;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
matriks_c[i][j] = 0;
for (k = 0; k < 2; k++)
matriks_c[i][j] += matriks_a[i][k] * matriks_b[k][j];
}
}
}
void transpos_matriks(int matriks_c[][2], int trans[][2])
{
int i,j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
trans[j][i] = matriks_c[i][j];
}
int main()
{
int matriks_a[2][2], matriks_b[2][2], matriks_c[2][2], trans[2][2];
int i,j;
printf("Program Perkalian dan Transpose Matriks (2*2) \n\n");
input_matriks(matriks_a, matriks_b);
kali_matriks(matriks_a, matriks_b, matriks_c);
transpos_matriks(matriks_c, trans);
printf("\nHasil Perkalian Matrik A x B = (Matrik C) : \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
printf("%3d", matriks_c[i][j]);
printf("\n");
}
printf("\nHasil Transpose matrik C adalah: \n");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
printf("%3d", trans[i][j]);
printf("\n");
}
getch();
return 0;
}