Matrix Multiplication

/* with class */
#include<iostream>
using namespace std;

class matrix {

	/* Declaration of two dimensional array */
	int a[3][3], b[3][3], ans[3][3];

	public:
		matrix() {
			cout << "Enter data for first array:" << endl;
			for(int i = 0; i < 3; i++)
				for(int j = 0; j < 3; j++)
					cin >> a[i][j];
			cout << "Enter data for second array:" << endl;
			for(int i = 0; i < 3; i++)
				for(int j = 0; j < 3; j++)
					cin >> b[i][j];
		}

		void multiplication() {
			cout << "After matrix multiplication" << endl;
			for(int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					ans[i][j] = 0;
					for(int k = 0; k < 3; k++)
						ans[i][j] += a[i][k] * b[k][j];
					cout << ans[i][j] << "\t";
				}
				cout << endl;
			}
		}
};

int main() {
	cout << "Program for calculation of Matrix Multiplication" << endl;
	matrix mtMul = matrix();
	mtMul.multiplication();
	return 0;
}


/****** Output ******/

Enter data for first array:


1


2


3


4


5


6


7


8


9


Enter data for second array:


4


4


4


4


4


4


4


4


4


After matrix multiplication


24 24 24


60 60 60


96 96 96

Recommended for you