#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语言二维数组的转置
内容版权声明:除非注明,否则皆为本站原创文章。