//#include "stdafx.h"//vc++6.0加上这一行.
#include
using namespace std;
int main(void){
int a[3][3],i,j,x;
cout << "Type 9 integers...\n";
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cin >> x;
cout << (a[j][i]=x) << ' ';
}
cout << endl;
}
cout << "After the transpose:\n";
for(i=0;i<3;i++){
for(j=0;j<3;cout << a[i][j++] << ' ');
cout << endl;
}
return 0;
}
#include
using namespace std;
const int N = 3;
void reverse(int arr[N][N])
{
int temp[N][N];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
temp[i][j] = arr[j][i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
arr[i][j] = temp[i][j];
}
void output(int arr[N][N])
{
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < N; ++j)
cout << arr[i][j] << " ";
cout << endl;
}
}
int main()
{
int num[N][N];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
cin >> num[i][j];
output(num);
reverse(num);
output(num);
return 0;
}
#include
int main()
{
int a[3][3],i,j,t;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("原始矩阵为:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d ",a[i][j]);
printf("\n");
}
for(i=0;i<3;i++)
for(j=0;j {
t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
printf("转置后的矩阵为:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d ",a[i][j]);
printf("\n");
}
return 0;
}