C++ Program to Multiply Two Matrix

C++ Program to Multiply Two Matrix

Write C++ Program to Multiply Two Matrix

// CPP Program to Multiply Two Matrix

#include <iostream>

using namespace std;

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];

	cout << "Matrix A :--> \n";
	for(i = 0;i < 3; i++)
	{
		for( j = 0; j < 3; j++)
		{
			cout << A[i][j] << " ";
		}
		cout << endl;
	}

	cout << "\n\nMatrix B :--> \n";
	for(i = 0;i < 3; i++)
	{
		for( j = 0; j < 3; j++)
		{
			cout << B[i][j] << " ";
		}
		cout << endl;
	}

	// 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]);
			}
		}
	}

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

	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