#include
using namespace std;
typedef struct
{int*pMat;
int row,col;}MAT,*pMAT;
void 生成矩阵A(MAT&a)
{
int i,j;
a.pMat=new int[a.row*a.col];
int *p=a.pMat;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
p[i*4+j]=(i+1)*30+3*j;
}
void 生成矩阵B(MAT&a)
{int i,j;
a.pMat=new int[a.row*a.col];
int *p=a.pMat;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
p[i*4+j]=(i+1)*30+2*j;
}
void 显示矩阵(char *str,MAT&a)
{int i,j;
cout<<str<<endl;
int*p=a.pMat;
for(i=0;i<3;i++)
{for(j=0;j<4;j++)
cout<<p[4*i+j]<<" ";
cout<<endl;}
}
void 矩阵相减(MAT&a,MAT&b,pMAT c)
{
int i,j;
int*p1=a.pMat;
int*p2=b.pMat;
c->pMat=new int[12];
int*p3=c->pMat;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
p3[i*4+j]=p1[4*i+j]-p2[4*i+j];
}
void main()
{
int m=3,n=4;
MAT A={0,m,n},B={0,m,n};
pMAT C=new MAT;
生成矩阵A(A);
生成矩阵B(B);
矩阵相减(A,B,C);
显示矩阵("A:",A);
显示矩阵("B:",B);
显示矩阵("C=A-B:",*C);
delete A.pMat;
delete B.pMat;
delete C->pMat;
delete C;
system("pause");
}