#include
#include
#include
#include
#include
#include
#define maxsize 100
#define m 2
#define n 3
typedef int elemtype;
typedef struct{
int i,j;
elemtype e;
}Triple;
typedef struct{
Triple date[maxsize+1];
int mu,nu,tu;
}TSMatrix;
void change(TSMatrix &t,elemtype a[m][n]){
int k=1;
t.mu=m;
t.nu=n;
t.tu=0;
for(int e=0;efor(int s=0;sif(a[e][s]!=0)
{
t.date[k].i=e;
t.date[k].j=s;
t.date[k].e=a[e][s];
t.tu++;
k++;
}
}
}
void DipMat(TSMatrix t){
cout<<"行号"<<" "<<"列号"<<" "<<"值\n";
for(int k=0;k" "<" "<"\n";
}
}
void DipMatjz(TSMatrix t){
int x=1,a[n][m],s,y;
for(y=0;yfor(s=0;sif(t.date[x].i==y&&t.date[x].j==s)
a[y][s]=t.date[x].e;
else
a[y][s]=0;
for(y=0;yfor(s=0;s" ";
cout<<"\n";
}
}
void z(TSMatrix m,TSMatrix &T){
int num[n+1],cpot[maxsize],col=1,x;
T.mu=m.nu;
T.nu=m.mu;
T.tu=m.tu;
if(T.tu){
for(col=1;col<=m.nu;++col)
num[col]=0;
for(x=1;T<=m.tu;T++)
++num[m.date[x].j];
cpot[1]=1;
for(col=2;col<=m.nu;++col)
cpot[col]=cpot[col-1]+num[col-1];
for(x=1;x<=t.tu;x++){
col=m.date[x].j;
y=copt[col];
T.date[y].i=m.date[x].j;
T.date[y].i=m.date[x].j;
T.date[y].e=m.date[x].e;
copt[col]++;
}
}
}
void main(){
cout<<"请输入"<"行"<"列矩阵:\n";
elemtype a[m][n];TSMatrix t,p;
for(int e=0;efor(int s=0;s>a[e][s];
change(t,a);
DipMat(t);
z(t,p);
cout<<"转置后矩阵为:\n";
DipMatjz(p);
}
变量m被宏m替换了,变量名或者宏名字改掉一个