现在的位置: 首页 > 综合 > 正文

笔试题五:实现输出矩阵 二维数组

2018年04月09日 ⁄ 综合 ⁄ 共 275字 ⁄ 字号 评论关闭

实现输出:

7  8  9  10

6  1  2  11

5  4  3  12

16 15 14 13

最简单的是采用定制输出:

 

int main()
{
	int cnt=1;int *p; int a[4][4]={{7,8,9,10},{6,1,2,11},{5,4,3,12},{16,15,14,13}};
	p=a[0];
	cout<<"the matrix is:"<<endl;
	while (*p && cnt<= 16)
	{
		cout<<*p<<" ";
		p++;
		if (cnt %4 ==0)
		{
			cout<<endl;
		}
		cnt++;
	}
	system("pause");
	return 0;
}

 

抱歉!评论已关闭.