题解 | #矩阵转置#

矩阵转置

http://www.nowcoder.com/practice/0fe4d131737d4138912c3b5df8569245

#include using namespace std;

int main(){ int n; cin >> n; int a[100][100]; //建立二维数组 for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int temp; cin >> temp; //输入数据 a[i][j] = temp; } } for(int i = 0; i < n; i++){ //转置 for(int j = i; j < n; j++){ if(i != j){ int temp = a[i][j]; a[i][j] = a[j][i]; a[j][i] = temp; } } } for(int i = 0; i < n; i++){ for(int j = 0; j <n; j++){ cout << a[i][j] << " "; } cout << endl; } return 0; }

全部评论

相关推荐

2025-12-17 12:08
门头沟学院 产品经理
牛客85811352...:1希音不知道算不算大厂 2完全符合,过得很舒服, 3确实只有杂活 领导找我续签到明年3、4月我要继续吗。主要是边实习边秋招这段时间还是有点累
什么是优秀的实习经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务