二维数组变一维
<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>
總結
- 上一篇: 获取数组元素的个数
- 下一篇: 计算n!中结尾零的个数