二维数组 [英] two dimensional arrays

查看:110
本文介绍了二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有简单的问题PLZ解决。我想打印以下输出。在2d阵列。

1 8 9 16

2 7 10 15

3 6 11 14

4 5 12 13


任何人都可以解决这个prblm发送。这个问题的答案。 PLZ

i将感激不尽2。

解决方案


hi,

i有简单问题plz求解。我想打印以下输出。在2d阵列。

1 8 9 16

2 7 10 15

3 6 11 14

4 5 12 13


任何人都可以解决这个prblm发送。这个问题的答案。 PLZ

我将感激你2。






您可以采用4x4二维数组并以[0] [ 0] = 1 ..... a [4] [4] = 13。你试过一些代码吗?我可以帮助你完成该代码。我无法根据本论坛的规则编写完整的代码。


问候


基本上你在这个矩阵中徘徊;每当你打到''墙''时你就会改变y方向
。单个循环和一些if语句可以完成这项工作:

展开 | 选择 | Wrap | 行号


另外,请注意你的2D阵列以这种方式存在于记忆中:


1 8 9 16 2 7 10 15 3 6 11 14 4 5 12 13


你可以将它视为一维数组,每行只显示4个数字。


C ++实际上只有一维数组。 int [4]数组有4个元素,其中每个元素都是int。 int [4] [4]仍然是一个包含4个元素的数组,但是每个元素都是一个4 int的数组。


数组在内存中连续作为元素0 1 2 3。 / BLOCKQUOTE>

hi,
i have simple problem plz solve. i want to print the following output. in 2d arrays.
1 8 9 16
2 7 10 15
3 6 11 14
4 5 12 13

can anybody solve this prblm send. this question answer. plz
i will b grateful 2 u.

解决方案

hi,
i have simple problem plz solve. i want to print the following output. in 2d arrays.
1 8 9 16
2 7 10 15
3 6 11 14
4 5 12 13

can anybody solve this prblm send. this question answer. plz
i will b grateful 2 u.

Hi,

You can take 4x4 two dimensional array and insert values in such a manner that a[0][0]=1 .....a[4][4]=13. Have you tried some code?. As I can help you in that code. I cannot write full code according the rule of this forum.

Regards


Basically you''re zig-zagging through that matrix; every time you hit a ''wall'' you
change the y-direction. A single loop and a few if-statements can do the job:

Expand|Select|Wrap|Line Numbers


Also, be aware that your 2D array is in memory this way:

1 8 9 16 2 7 10 15 3 6 11 14 4 5 12 13

You could treat it as a 1D array and just display 4 numbers per line.

C++ really only has 1D arrays. An int [4] array has 4 elements where each element is an int. An int [4][4] is still an array of 4 elements but each element is an array of 4 int.

Arrays are in memory contiguously as element 0 1 2 3.


这篇关于二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆