C Program to Multiply Two Matrix

Write C Program to Multiply Two Matrix

// C Program to Multiply Two Matrix

#include <stdio.h>

int main()
{
	int A[3][3]={{1, 1, 1}, {2, 2, 2}, {3, 3, 3}};
	int B[3][3]={{1, 1, 1}, {2, 2, 2}, {3, 3, 3}};
	int i, j, k, C[3][3];

	printf("Matrix A :--> \n");
	for(i = 0;i < 3; i++)
	{
		for( j = 0; j < 3; j++)
		{
			printf("%d  ", A[i][j]);
		}
		printf("\n");
	}

	printf("\n\nMatrix B :--> \n");
	for(i = 0;i < 3; i++)
	{
		for( j = 0; j < 3; j++)
		{
			printf("%d  ", B[i][j]);
		}
		printf("\n");
	}

	// Multiplying Matrix
	for(i =0 ;i < 3; i++)
	{
		for(j = 0;j < 3; j++)
		{
            C[i][j]=0;
			for(k = 0; k < 3; k++)
			{
				C[i][j] = C[i][j] + (A[i][k] * B[k][j]);
			}
		}
	}

    printf("\n\nResultant Matrix :--> \n");
	for(i = 0; i < 3; i++)
	{
		for(j = 0; j < 3; j++)
		{
			printf("%d  ", C[i][j]);
		}
		printf("\n");
	}

	return 0;
}

Output:

Matrix A :-->
1  1  1
2  2  2
3  3  3


Matrix B :-->
1  1  1
2  2  2
3  3  3


Resultant Matrix :-->
6  6  6
12  12  12
18  18  18

≪ Previous | Next ≫