Answer to Question #229353 in C for ABDUL RAZZAQUE

Question #229353

Write a program to obtain the multiplication of a 4 x 4 matrix. 


1
Expert's answer
2021-08-25T05:46:49-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

abdul razzaque
26.08.21, 08:59

Lots of thanks my dear website, really cool work

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS