转置一个3*3数组

wuquanzhanjiang 2009-11-08 08:54:48
#include<iostream>
#include <string.h>
using namespace std;
extern int s[3][3]={1,2,3,4,5,6,7,8,9};
void tran();
int main()
{

int count=0;
int word;
for(int n=0;n<3;++n)
for(int m=0;m<3;++m)
{
cin>>word;
s[n][m]=word;
cout<<s[n][m]<<" ";
count++;
if(count%3==0)
cout<<endl;
}

tran();
return 0;
}
void tran()
{


int count=0;
for(int n=0;n<3;++n)
for(int m=0;m<3;++m)
{
s[m][n]=s[n][m];
cout<<s[n][m]<<" ";
count++;
if(count%3==0)
cout<<endl;
}
}

编译通过,求一个3*3矩阵转置的函数,在main中输入数据
...全文
100 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lhf1985314 2009-11-09
  • 打赏
  • 举报
回复
tran()函数里的s[m][n]=s[n][m]不对,当n开始变化的时候,一开始输入的数组值已经变了,换一个数组保存转置数组就可以了。随便声明一个a[3][3]就可以了

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧