您的位置:首页 > 其它

二维数组变一维

2015-09-25 20:31 204 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: