矩阵翻转

矩阵翻转90度的操作。

#include <iostream>
#include <iomanip>
#define N 3
using namespace std;

void main()
{
 int a[N][N] = {1,2,3,4,5,6,7,8,9};

 int b[N][N];

 for(int i = 0;i<N;i++)
 {
  for(int j = 0;j < N;j++)
  {
   b[j][i] = a[i][N-1-j];//翻转操作
  }
 }
 
 cout<<"原始矩阵为:"<<endl;
 for(i = 0;i < N;i++)
 {
  for(int j = 0;j<N;j++)
  {
   cout<<setw(3)<<a[i][j];
  }
  cout<<endl;
 }

 cout<<"逆时针翻转90度后矩阵为:"<<endl;//顺时针同理
 for(i = 0;i < N;i++)
 {
  for(int j = 0;j<N;j++)
  {
   cout<<setw(3)<<b[i][j];
  }
  cout<<endl;
 }
}

posted @ 2013-11-12 14:29  c plus plus  阅读(367)  评论(0)    收藏  举报