#include <iostream.h>
#include <iomanip.h>
int ** create(int m,int n)
{
int i,j;
int **p = new int*[m];
cout <<"輸入矩陣"<<endl;
for(i=0;i<m;i++)
{
p[i] =new int[n];
for(j=0;j<n;j++)
{
cin>>p[i][j];
}
}
return p;
}
void show(int **p,int m,int n)
{
int i,j;
cout <<"輸出矩陣"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<p[i][j]<<" ";
}
cout <<endl;
}
}
void Mut(int **pa,int am,int an,int **pb,int bm,int bn) //乘函數
{
int i,j,k,s,cm,cn;
cm = am;
cn = bn;
cout <<"asdf"<<am<<bm;
int **pc = new int*[cm];
for(i=0;i<cm;i++)
{
pc[i] = new int[cn];
for (j=0;j<cm;j++)
{
s=0;
for(k=0;k<an;k++)
s+=pa[i][k]*pb[k][j];
pc[i][j]=s;
}
}
show(pc,cm,cn);
}
void main()
{
int am,an,bm,bn;
int **pa,**pb;
cout <<"建立矩陣A"<<endl;
cout <<"請輸入矩陣行數"<<endl;
cin >>am;
cout <<"請輸入矩陣列數"<<endl;
cin >>an;
pa = create(am,an);
show(pa,am,an);
cout <<"建立矩陣B"<<endl;
cout <<"請輸入矩陣行數"<<endl;
cin >>bm;
cout <<"請輸入矩陣列數"<<endl;
cin >>bn;
pb = create(bm,bn);
show(pb,bm,bn);
Mut(pa,am,an,pb,bm,bn);
}ios