代码:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j;
int t,a[50][50];
scanf("%d\n",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
for(i=0;i<n;i++)
for(j=0;j<=i;j++)
{
if(i!=j)
{
t=a[j][i];
a[j][i]=a[i][j];
a[i][j]=t;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}
输出结果:
3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 8
3 6 9
--------------------------------
Process exited with return value 0
Press any key to continue . . .