Ini 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;
}
Monday, March 11, 2013
Subscribe to:
Post Comments (Atom)
Nozh_Statistik
About Me
Translate
Facebook Nozhbitha
Twitter-nozhbitha
Followers
copyright by Nozhbitha. Powered by Blogger.
Labels
- ALPRO (9)
- Buah tangan (5)
- ISENG_ISENG (1)
- Latihan alpro (30)
- Linux (1)
- Nozh Gallery (2)
- Nozhbitha (29)
- Pemrograman C++ (7)
- tentang alpro (12)
0 comments:
Post a Comment