问题如图
Code
#include<stdio.h>
#define COL 3
#define ROW 3
void inputData(int array[][COL]);
void printAll(int array[][COL]);
void transpositionArray(int array[][COL]);
int main(){
int array[ROW][COL]={0};
inputData(array);
printf("原数组
");
printAll(array);
transpositionArray(array);
printf("已转置数组
");
printAll(array);
system("pause");
return 0;
}
void inputData(int array[][COL]){
int x,y;
for(y=0;y<ROW;y++){
for(x=0;x<COL;x++){
printf("请输入第%d行第%d列数据:",y+1,x+1);
fflush(stdin);
scanf("%d",&array[y][x]);
}
}
}
void transpositionArray(int array[][COL]){
int temp=0;
int x,y;
for(y=1;y<ROW;y++){
for(x=0;x<y;x++){
temp=array[y][x];
array[y][x]=array[x][y];
array[x][y]=temp;
}
}
}
void printAll(int array[][COL]){
int x,y;
for(y=0;y<ROW;y++){
for(x=0;x<COL;x++){
printf("%d ",array[y][x]);
}
printf("
");
}
}
演示图