Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main() {
- int Ar, Ac, Br, Bc;
- cout << "Enter the size of \"A\" matrix (x * y): ";
- cin >> Ar >> Ac;
- cout << "Enter the size of \"B\" matrix (y * z): ";
- cin >> Br >> Bc;
- if (Ac != Br) {
- cout << "Error, size of the Matrices are not satisfiable;" << endl;
- exit(1);
- }
- else {
- int A[Ar][Ac], B[Br][Bc], C[Ar][Bc];
- cout << "Enter the A-Matrix (x * y elements): ";
- for (int i = 0; i < Ar; i++)
- for (int j = 0; j < Ac; j++)
- cin >> A[i][j];
- cout << "Enter the B-Matrix (y * z elements): ";
- for (int i = 0; i < Br; i++)
- for (int j = 0; j < Bc; j++)
- cin >> B[i][j];
- for (int i = 0; i < Ar; i++)
- for (int j = 0, sum = 0; j < Bc; j++) {
- for (int k = 0; k < Ac; k++)
- sum += (A[i][k] * B[k][j]);
- C[i][j] = sum;
- sum = 0;
- }
- cout << "Printing the Product of A and B Matrices: " << endl;
- for (int i = 0; i < Ar; i++) {
- for (int j = 0; j < Bc; j++)
- cout << C[i][j] << "\t";
- cout << endl;
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement