C语言经典算法 - 多维矩阵转一维矩阵的代码

下边内容内容是关于C语言经典算法 - 多维矩阵转一维矩阵的内容,应该能对码农也有好处。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int arr1[3][4] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}};
int arr2[12] = {0};
int row, column, i;
printf("原二维资料:n");
for (row = 0; row < 3; row++)
{
for (column = 0; column < 4; column++)
{
printf("%4d", arr1[row][column]);
}
printf("n");
}
printf("n以列为主:");
for (row = 0; row < 3; row++)
{
for (column = 0; column < 4; column++)
{
arr2[i] = arr1[row][column];
}
}
for (i = 0; i < 12; i++)
printf("%d ", arr2[i]);
printf("n以行为主:");
for (row = 0; row < 3; row++)
{
for (column = 0; column < 4; column++)
{
arr2[i] = arr1[row][column];
}
}
for (i = 0; i < 12; i++)
printf("%d ", arr2[i]);
printf("n");
return 0;
}




 

posted on 2019-03-31 22:51  土豆师傅  阅读(215)  评论(0编辑  收藏  举报

导航