// multiplication of matrices
#include<iostream.h>
void main()
{
int a[3][3], b[3][3], c[3][3] = {0}, i, j, k;
// initializing 2 D array a with user defined values
cout<<"Enter values for array A"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for a["<<i<<"]["<<j<<"]:";
cin>>a[i][j];
}
}
cout<<endl<<endl;
// initializing 2 D array b with user defined values
cout<<"Enter values for array B"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for b["<<i<<"]["<<j<<"]:";
cin>>b[i][j];
}
}
cout<<endl<<endl;
// origional array A
cout<<"displaying origional array A:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// origional array A
cout<<"displaying origional array B:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// multiplication of A and B
cout<<"A x B = "<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
c[i][j]= c[i][j] + (a[i][k]*b[k][j]);
}
cout<<c[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
}
#include<iostream.h>
void main()
{
int a[3][3], b[3][3], c[3][3] = {0}, i, j, k;
// initializing 2 D array a with user defined values
cout<<"Enter values for array A"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for a["<<i<<"]["<<j<<"]:";
cin>>a[i][j];
}
}
cout<<endl<<endl;
// initializing 2 D array b with user defined values
cout<<"Enter values for array B"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"enter value for b["<<i<<"]["<<j<<"]:";
cin>>b[i][j];
}
}
cout<<endl<<endl;
// origional array A
cout<<"displaying origional array A:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// origional array A
cout<<"displaying origional array B:"<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
// multiplication of A and B
cout<<"A x B = "<<endl<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
c[i][j]= c[i][j] + (a[i][k]*b[k][j]);
}
cout<<c[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
}
0 comments:
Post a Comment