<span style="font-size:18px;">#include<iostream>
using namespace std;
int main()
{
int i, j;
int array[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
cout << "输出数组" << endl;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
cout << array[i][j] << "\t";
cout << endl;
}
int a[9] = { 0 };
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
i = col + row * 3;
a[i] = array[row][col];
}
}
for (int i = 0; i < 9; i++)
cout << a[i] << "\t";
system("pause");
return 0;
}</span>
二维数组变一维
最新推荐文章于 2022-03-14 21:34:17 发布