#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define maxsize 3
#define transsize 3
void trans(int A[][maxsize],int B[][transsize],int m, int n){
printf("转置前----\n");
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
printf("%d\t",B[i][j]);
}
printf("\n");
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
B[j][i] = A[i][j];
}
}
printf("转置后----\n");
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
printf("%d\t",B[i][j]);
}
printf("\n");
}
}
int main(){
int a[][maxsize]={{1,2,3},{4,5,6},{7,8,9}};
int b[][transsize]={{1,2,3},{4,5,6},{7,8,9}};
trans(a,b,transsize,maxsize);
return 0;
}
c语言二维数组的转置
最新推荐文章于 2024-08-31 20:59:22 发布