Kode Program Perkalian Matriks
Desember 01, 2012Ini aku share source code buat perkalian matriks
Enjoy the code! And don't forget to learn it yaaak:)
#include <stdio.h>
int main()
{
int b1,k1,b2,k2;
int i,j,k;
printf("\t-----*Program Perkalian Dua Matriks*-----\n");
printf("Masukan baris dan kolom matriks I :\n");
printf("Baris M1: ");
scanf("%d",&b1);
printf("Kolom M1 : ");
scanf("%d",&k1);
int M1[b1][k1];
for(i=0;i<b1; i++) {
for(j=0; j<k1;j++){
printf("\tBaris[%d] :", i+1);
printf(" Kolom[%d] :", j+1);
scanf("%d",&M1[i][j]);
}
}
for(i=0;i<b1; i++) {
for(j=0; j<k1;j++){
printf("%d\t", M1[i][j]);
}
printf("\n");
}
printf("\n\nMasukan baris dan kolom matriks II :\n");
printf("Baris M2 :");
scanf("%d", &b2);
printf("Kolom M2 :");
scanf("%d",&k2);
int M2[b2][k2];
for(i=0;i<b2; i++) {
for(j=0; j<k2; j++) {
printf("\tBaris[%d] :", i+1);
printf("Kolom[%d] :", j+1);
scanf("%d", &M2[i][j]);
}
}
for(i=0;i<b2; i++) {
for(j=0; j<k2; j++) {
printf("%d\t", M2[i][j]);
}
printf("\n");
}
int HSL[b1][k2],result;
if (k1==b2){
for (i=0; i<b1;i++){
for (j=0 ; j<k2;j++){
result=0;
for(k=0;k<b2;k++){
result=result+(M1[i][k]*M2[k][j]);
}
HSL[i][j]=result;
}
}
printf("\n\n\t *~~~~~RESULT~~~~~*\n");
HSL[i][j]=result;
for (i=0; i<b1; i++){
printf("\t[ ");
for (j=0;j<k2 ;j++){
printf("%d ",HSL[i][j]);
}
printf("]\n");
}
}
getch();
return 0;
}
Warm Regards,
0 komentar