### 2D array

How can I output 2D array (8*8) but in order?

0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31
32 33 34 45 46 47 48 49
50 51 52 53 54 55 56 57
58 59 60 61 62 63 64 64
65 66 67 68 69 70 71 72

 ``1234567891011121314151617181920212223242526272829`` ``````#include using namespace std; void setarray(int ma[8][8],int size,int jsize) { for (int i=0;i

I cannot find out a solution, help please.
Last edited on
Help!!!
What do you mean by "in order"?
You almost have it..

 ``12345678910111213141516171819202122232425262728293031323334`` ``````// 2D Array.cpp : main project file. #include using namespace std; void setarray(int ma[8][8],int size,int jsize) { for (int i=0;i
@firedraco

respectively

0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31
32 33 34 45 46 47 48 49
50 51 52 53 54 55 56 57
58 59 60 61 62 63 64 64
65 66 67 68 69 70 71 72
Last edited on
If I have understood what you want then you can use the following code to fill the array

 ``123456789`` ``````int n = 0; for ( int i=0; i < 8; i++ ) { for ( int j=0; j < 8; j++, n = ( n == 34 ) ? 45 : n + 1 ) { ma[i][j] = n; } }``````

The output is

 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

I am sorry. I have not seen that 64 is duplicated in your output

 58 59 60 61 62 63 64 64 65 66 67 68 69 70 71 72

Is it a typo?
Last edited on
Topic archived. No new replies allowed.