#include <stdio.h>
#include <conio.h>
#define M 4
#define N 4
void main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
clrscr();
int i,k;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int a[M][N]=
{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}};
int b[M][N];
for(i=0;i<M;i++)
for(k=0;k<N;k++) b[i][k]=a[k][i];
for(i=0;i<M;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{ for(k=0;k<N;k++) printf("%5d",b[i][k]);
printf("\n");
}
}
上例中定义了2个数组,若不借助第二个数组,可以用如下程序实现:
#include <stdio.h>
#include <conio.h>
#define M 4
#define N 4
void main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
clrscr();
int i,k,t;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int a[M][N]=
{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}};
int b[M][N];
for(i=0;i<M;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(k=0;k<i;k++)
{t=a[k][i];a[k][i]=a[i][k];a[i][k]=t;}
for(i=0;i<M;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{ for(k=0;k<N;k++) printf("%5d",a[i][k]);
printf("\n");
}
}