Berikut Source Code penjumlahan Matriks Bahasa C:
#include stdio.h
#include stdlib.h
int main () {
int size = 128; //besar matiks dapat diubah sesuai dengan keinginan blogger
int a[size][size], b[size][size];
int hasil[size][size], i, j, acak;
printf("MATRIK A \n");
for (i=0; i
acak=rand() % 16; // fungsi random integer [0..15]
a[i][j]=acak;
printf("a[%d,%d] = %d ", i+1, j+1, acak);
}
printf("\n")
printf("Masukkan Matrik B \n");
for (i=0; i
acak=rand() % 16; //fungsi random integer [0..15]
b[i][j]=acak;
printf("b[%d,%d] = %d ", i+1, j+1, acak);
}
for (i=0; i
hasil [i][j] = a[i][j] + b[i][j];
}
printf("\n")
printf("Hasil Penjumlahan Matrik Adalah \n");
for (i=0;i
for (j=0; j
printf ("%d ", hasil [i][j]);
}
printf ("\n");
}
}
Berikut Source Code Perkalian Matrik Bahasa C :
#include
#include stdlib.h
int main () {
int size = 128;
int a[size][size], b[size][size];
int hasil[size][size], i, j,k,sum, acak;
printf("MATRIK A \n");
for (i=0; i
acak=rand() % 16; //fungsi random integer [0..15]
a[i][j]=acak;
printf("a[%d,%d] = %d ", i+1, j+1, acak);
}
printf("\n")
printf("MATRIK B \n");
for (i=0; i
acak=rand() % 16; //fungsi random integer [0..15]
b[i][j]=acak;
printf("b[%d,%d] = %d ", i+1, j+1, acak);
}
for (i=0; i
hasil[i][j]=0;
for (k=0; k
hasil[i][j] += a[i][k] * b[k][j];
}
}
printf("\n");
printf("Hasil Perkalian Matrik Adalah \n");
for (i=0;i
for (j=0; j
printf ("%d ", hasil [i][j]);
}
printf ("\n");
}
}
Jika blogger ingin mengganti input matriks sesuai dengan yang agan inginkan tinggal ganti input matrik A dan B menjadi :
printf("MATRIK A \n");
for (i=0; i
printf("a[%d,%d]: ", i+1, j+1);
scanf ("%d", &a[i][j]);
}
No comments:
Post a Comment