关于矩阵的旋转(逆时钟 90°)

来源:互联网 发布:php 接收不到post参数 编辑:程序博客网 时间:2024/06/10 11:40

下面是对一个4X4的矩阵的旋转算法:

#include<iostream>using namespace std;#define N 4template<class T>void CoutMatrix(T a[N][N]){int i,j;for (i = 0;i<N;i++){for (j = 0;j<N;j++){cout<<a[i][j]<<" ";}cout<<endl;}cout<<endl;}void main(){int i,j;int a[N][N] = {0,1,0,0,0,2,3,0,0,4,0,0,0,0,0,0};//定义一个4X4的矩阵int T[N][N];CoutMatrix(a);//*****************************************//for (i=0;i<N;i++){for (j = 0;j<N;j++){T[N-j-1][i] = a[i][j];}}//旋转的实现//****************************************//CoutMatrix(T);}



结论:目标矩阵T的列标为:源矩阵的行标,目标矩阵的行标为:矩阵的行标-1-源矩阵的列标

原创粉丝点击