0% found this document useful (0 votes)
28 views2 pages

C++ Program To Multiply Two Square Matrices

This C++ program multiplies two square matrices of user-defined size. It takes input for the elements of the two matrices, initializes a third matrix to store the product, and uses a nested for loop to calculate each element of the product matrix as the sum of the element-wise multiplication of the rows of the first and columns of the second. It then prints out the resulting product matrix.

Uploaded by

Ammar Ahmad
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)
28 views2 pages

C++ Program To Multiply Two Square Matrices

This C++ program multiplies two square matrices of user-defined size. It takes input for the elements of the two matrices, initializes a third matrix to store the product, and uses a nested for loop to calculate each element of the product matrix as the sum of the element-wise multiplication of the rows of the first and columns of the second. It then prints out the resulting product matrix.

Uploaded by

Ammar Ahmad
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/ 2

C++ program to multiply two square matrices.

#include <iostream>
using namespace std;
int main()
{
int x[10][10],y[10][10],mul[10][10],row,col,i,j,k;
cout<<"Enter the Number of Rows = ";
cin>>row;
cout<<"Enter the Number of Column = ";
cin>>col;
cout<<"Enter the First Matrix Element = \n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>x[i][j];
}
}
cout<<"Enter the Second Matrix Element = \n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>y[i][j];
}
}
cout<<"Multiply of the Matrix=\n";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
mul[i][j]=0;
for(k=0;k<col;k++)
{
mul[i][j]+=x[i][k]*y[k][j];
}
}
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<mul[i][j]<<" ";
}
cout<<"\n";
}
}

You might also like