Implement a program of matrix Multiplication in c++


Implement a program of matrix Multiplication
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a[10][10],b[10][10],c[10][10],m,n,p,q,k,i,j;
cout << "\nEnter the rows and column of matrix A : ";
cin >> m >> n;
cout << "\nEnter the no. of rows and column of matrix B : ";
cin >>p >> q;
if(n==p)
{
cout << "\n Enter element of matrix A : \n";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin >> a[i][j];
cout << "\n Enter the element of matrix B : \n";
for(i=0;i<p;i++)
for(j=0;j<q;j++)
cin >> b[i][j];
cout << "Matrix A is \n";





for (i=0;i<m;i++)
{
cout << "\n";
for(j=0;j<n;j++)
cout << a[i][j] <<" ";
}
cout << "\nMatrix B is \n";
for(i=0;i<p;i++)
{
cout << "\n";
for(j=0;j<q;j++)
cout << b[i][j]<< " ";
}
cout << "\nProduct of Two marices is : \n";
for(i=0;i<m;i++)
{
cout <<"\n";
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
cout << c[i][j]<< " ";
}
}
}
else
{
cout << "\n Matrices cannot be multipled syntax error..!!" ;
}
getch();
return 0;
}

Comments

Popular Posts