#include<stdio.h>
void main()
{
int a[3][4] = { {1,2,3},{4,5,6},{7,8,9} };
int b[4][3] = {0};
int zf = sizeof(a) / sizeof(a[0][0]);//总长
int row_len = sizeof(a) / sizeof(a[0]);//行数
int col_len = zf / row_len;//列数
int i, j, k=0,count=0;
for (i = 0; i <row_len;i++)
{
for (j = 0; j <col_len; j++)
{
count++;
printf("%3d",a[i][j]);
b[j][i] = a[i][j];//转置
if (count % col_len == 0)
{
printf("\n");
}
}
}
printf("--------------------------------\n");
count=0;
for (i = 0; i < col_len; i++)
{
for (j = 0; j < row_len; j++)
{
count++;
printf("%3d",b[i][j]);
if (count % row_len == 0)
{
printf("\n");
}
}
}
}
我用sizeof()函数求数组元素总个数,再求出每一行的和每一列的元素个数,用来控制循环。
行列式转置:
一个行列式事一个3*4的,经过转置后就是4*3的,行列式本身的值不变。