文章目录
矩阵操作试题(C++/Python) 系列目录:矩阵操作试题(C++/Python)——目录
0. 前言
给出一个矩阵,得到他的转置矩阵,输入以及要求输出如下:
e.g.0.1 示例1 3*3矩阵
Input
1 2 3
4 5 6
7 8 9
Output:
3 6 9
2 5 8
1 4 7
e.g.0.2 示例2 4*4矩阵
Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
4 8 12 16
3 7 11 15
2 6 10 14
1 5 9 13
1. 程序C++版
Code.1.1 示例程序C++版
#include <iostream>
#define N 4
using namespace std;
void displayMatrix(int mat[N][N]);
void rotateMatrix(int mat[][N])
{
for (int x = 0; x < N / 2; x++)
{
for (int y = x; y < N-x-1; y++)
{
int temp = mat[x][y];
mat[x][y] = mat[y][N