Here's a little problem I came across. If you have the time and are interested...
Populate a 2-D array exactly as shown below:
Provide the simples solution possible. Only stipulation is that the values must be in an array (no classes).Code:1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8
Here's my best stab at it:
Code:for( int i = 0; i < 9; i++ ){
for( int j = 0; j < (9-i); j++ )
mArray[i][j] = j+i+1;
for( int k = 0; k < i; k++ )
mArray[i][(9-i)+k] = k+1;
}