c语言矩阵转置函数套用 c语言矩阵的转置程序解题思路( 二 )


}
int main(void)
{
void transition(int array[][3]);
int i,j;
printf("请输入数据\n");
for(i=0;iN;i++)
for(j=0;jN;j++)
scanf("%d",array[i][j]);
printf("\n");
transition(array);
printf("调换数据如下\n");
for(i=0;iN;i++)
{
for(j=0;jN;j++)
printf("%5d",array[i][j]);
printf("\n");
}
return 0;
}
~~~~~~
我写c语言矩阵转置函数套用的代码c语言矩阵转置函数套用,c语言矩阵转置函数套用你自己参考吧c语言矩阵转置函数套用,很简单的
用C语言编写一个矩阵转置的函数,矩阵的行数和列数在程序中由用户输入,请问怎么写 , 非常感谢我的代码逻辑是:
矩阵行指针初值指向每行首地址,迭代依次取所有行指针指向值组成新行,所有行指针自增 。最终组合新的矩阵 。
#include stdio.h
#include malloc.h
int **getList(int row,int clo);//获取矩阵地址空间
void setNum(int **nList,int n);//填写数值
void prtList(int **nList,int row,int clo);//打印矩阵
int **zz(int **nList,int row,int clo);//转置函数
int main()
{
int row,clo,**nList=NULL,**nListSave=NULL;
printf("输入矩阵行列数:");
scanf("%d%d",row,clo);
nList=getList(row,clo);
setNum(nList,row*clo);
printf("输入的矩阵为:\n");
prtList(nList,row,clo);
printf("转置后的矩阵为:\n");
nListSave=zz(nList,row,clo);
free(nList);
nList=nListSave;
prtList(nList,clo,row);
return 0;
}
int **zz(int **nList,int row,int clo)
{
int *nSave=NULL,**listSave=NULL,**listp=nList,*p=NULL,i,j;
nSave=(int *)malloc(sizeof(int)*row*clo);
listSave=(int **)malloc(sizeof(int*)*clo);//倒置后的矩阵
p=nSave;
for(j=0;jclo;j++)
{
for(i=0;irow;i++)
{
*p++=*listp[i];
listp[i]=listp[i]+1;
}
}
for(i=0;iclo;i++)
listSave[i]=nSave[i*row];
for(i=0;irow;i++)
free(nList[i]);//释放原矩阵行空间
returnlistSave;
}
void prtList(int **nList,int row,int clo)
{
int i,j;
for(i=0;irow;i++)
{
for(j=0;jclo;j++)
printf("%d ",nList[i][j]);
printf("\n");
}
}
void setNum(int **nList,int n)
{
int *p=nList[0];
printf("填写矩阵中%d个数值:\n",n);
while(n--0)
scanf("%d",p++);
}
int **getList(int row,int clo)
{
int *nums,**nList,i;
nums=(int *)malloc(sizeof(int)*row*clo);
nList=(int **)malloc(sizeof(int*)*row);
for(i=0;irow;i++)
nList[i]=nums[i*clo];
return nList;
}
c语言如何通过定义函数来转置矩阵?#include stdio.h
int main()
{ struct aaa
{ int x;
【c语言矩阵转置函数套用 c语言矩阵的转置程序解题思路】int y;
};
struct aaa t,a[3][3]= {0,0,0,1,0,2,1,0,1,1,1,2,2,0,2,1,2,2};
int i,j;
for(i=0; i3; i++)
{ for(j=0; j3; j++)
printf("[%d,%d]",a[i][j].x,a[i][j].y);
printf("\n");
}
printf("after:\n");
for(i=0; i3; i++)
for(j=0; ji; j++)
{ t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
for(i=0; i3; i++)
{ for(j=0; j3; j++)
printf("[%d,%d]",a[i][j].x,a[i][j].y);
printf("\n");
}
return 0;
}
或:
#include stdio.h
struct aaa
{ int x;
int y;
};
void zhuanzhi(struct aaa a[][3])
{ struct aaa t;
int i,j;
for(i=0; i3; i++)
for(j=0; ji; j++)
{ t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
}
void prt(struct aaa a[][3])
{ int i,j;
for(i=0; i3; i++)
{ for(j=0; j3; j++)

推荐阅读