编写程序,实现矩阵(3行3列)的转置(即行列互换)

编写程序,实现矩阵(3行3列)的转置(即行列互换),第1张

#include<iostream.h>

void main()

{

int a[3][3],b[3][3]

int p=0

for(int i=0i<3i++)

{

for(int j=0j<3j++)

{

cin>>a[i][j]

b[j][i]=a[i][j]

}

}

cout<<"原矩阵为:"<<endl

for(int m=0m<3m++)

{

for(int n=0n<3n++)

{

cout<<a[m][n]<<"轿纯 "

p++

if(p%3==0)

cout<<endl

}

}

cout<<樱嫌endl

cout<<"转置后的矩脊帆手阵为:"<<endl

for(int c=0c<3c++)

{

for(int d=0d<3d++)

{

cout<<b[c][d]<<" "

p++

if(p%3==0)

cout<<endl

}

}

}

在祥含C语言中假设原数组为a,互换行列后的数组为b:

main()

{

int a [2][3]={{1,2,3},{4,5,6}}

int b [3][2],i,j

printf("Array a:\n")

for (i=0i<=1i++)

{

for(j=0j<=2j++)

{

printf("%5d",a[i][j])

b[j][i]=a[i][j]

}

printf("\n"谨罩笑)

}

printf("Array b:\n")

for(i=0i<=2i++)

{

for(j=0j<=1j++)

printf("%5d",b[i][j])

printf("\n"闷轮)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12351520.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存