13 14 15 16 4 8 12 16 1 5 9 13
#include <iostream>
using namespace std;
void swap(int &x,int &y) {
int k = x;
x = y;
y = k;
}
void Transpote(int array[][4],int n) {
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
swap(array[i][j],array[j][i]);
for(int i=0;i<n/2;i++)
for(int j=0;j<n;j++)
swap(array[i][j],array[n-i-1][j]);
}
int main() {
int array[4][4] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
cout<<array[i][j]<< " ";
cout<< endl;
}
cout<< endl;
Transpote(array,4);
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
cout<<array[i][j]<< " ";
cout<< endl;
}
return 0;
}原文:http://blog.csdn.net/zzucsliang/article/details/40961335