Write a program to obtain the multiplication of a 4 x 4 matrix.
#include <stdio.h>
#define N 4
void multiplyMatrices(int M1[][N], int M2[][N], int result[][N])
{
int i, j, k;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
result[i][j] = 0;
for (k = 0; k < N; k++)
result[i][j] += M1[i][k] * M2[k][j];
}
}
}
int main()
{
int M1[N][N] = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 } };
int M2[N][N] = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 } };
int result[N][N];
int i, j;
multiplyMatrices(M1, M2, result);
printf("Result\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
printf("%d ", result[i][j]);
printf("\n");
}
return 0;
}
Comments
Lots of thanks my dear website, really cool work
Leave a comment