0% found this document useful (0 votes)
37 views3 pages

ZZZZ

The document contains code to multiply two matrices. It first checks that the columns of the first matrix equals the rows of the second matrix. It then takes input for the elements of both matrices and stores them in arrays. Finally, it calculates the product of the matrices by iterating through the arrays and multiplying and summing the corresponding elements.

Uploaded by

KLDFJGL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

ZZZZ

The document contains code to multiply two matrices. It first checks that the columns of the first matrix equals the rows of the second matrix. It then takes input for the elements of both matrices and stores them in arrays. Finally, it calculates the product of the matrices by iterating through the arrays and multiplying and summing the corresponding elements.

Uploaded by

KLDFJGL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <iostream>

using namespace std;

int main() {

int c[10][10], z[10][10], mult[10][10], r1, c1, r2, c2;

cout << "Enter rows and columns for 1st matrix: ";

cin >> r1 >> c1;

cout << "Enter rows and columns for 2nd matrix: ";

cin >> r2 >> c2;

while (c1 != r2)

cout << "Error! column of 1st matrix not equal to row of 2nd.\n";

cout << "So Multiplication is not possible\n ";

cout << "Enter rows and columns for 1st matrix: ";

cin >> r1 >> c1;

cout << "Enter rows and columns for 2nd matrix: ";

cin >> r2 >> c2;

cout << endl << "Enter elements of matrix 1:" << endl;

for (int i = 0; i < r1; ++i)

for (int j = 0; j < c1; ++j)

cout << "Enter element c" << i + 1 << j + 1 << " : ";

cin >> c[i][j];

cout << endl << "Enter elements of matrix 2:" << endl;

for (int i = 0; i < r2; ++i)

for (int j = 0; j < c2; ++j)

cout << "Enter element z" << i + 1 << j + 1 << " : ";
cin >> z[i][j];}

for (int i = 0; i < r1; ++i)

for (int j = 0; j < c2; ++j)

mult[i][j] = 0;

for (int i = 0; i < r1; ++i)

for (int j = 0; j < c2; ++j)

for (int k = 0; k < c1; ++k)

mult[i][j] += c[i][k] * z[k][j];

cout << endl << "Output Matrix: " << endl;

for (int i = 0; i < r1; ++i)

for (int j = 0; j < c2; ++j)

cout << " " << mult[i][j];

if (j == c2 - 1)

cout << endl;

return 0;

You might also like