自由定义矩阵相乘问题
可以解决大部分问题
代码存在问题:定义了二维数组的最大规模,并不是可变数组
#include<iostream>
using namespace std;
void main()
{
int a[10][10]={0},b[10][10]={0},c[10][10]={0};
int i,j,m,n,k,x,y;
cout<<"please input the matrex_a that is m*n and matrex_b that is n*m"<<endl;
cout<<"please input m and n"<<endl;
cout<<"m=";
cin>>m;
cout<<"n=";
cin>>n;
cout<<"please input "<<m*n<<" numbers as matrix_a"<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"the matrix_a is :"<<endl;
for(i=0;i<m;i++){
for(j=0;j<n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
cout<<"please input "<<n*m<<" numbers as matrix_b"<<endl;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>b[i][j];
cout<<"the matrix_b is :"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
for(x=0;x<m;x++)
{
for(y=0;y<m;y++)
{
c[x][y]=0;
for(k=0;k<n;k++)
{
c[x][y]+=a[x][k]*b[k][y];
}
}
}
cout<<"the result of a*b is "<<endl;
for(x=0;x<m;x++)
{
for(y=0;y<m;y++)
cout<<c[x][y]<<" ";
cout<<endl;
}
}