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 35 36 37 38 39 40 41 42 43 44
|
#include<cstring>
#include <iostream>
#include<cstdlib>
using namespace std; //bad but going with the flow
int main()
{
const int c = 6;
const int r = 6;
int m2d[r*c] =
{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, 35}; //got rid of the example copy
int s1[18]; //slice 1
int s2[18]; // slice 2
int dx = 0; //inDeX counter.
for(int j = 0; j < r; j++)
{
for(int k = 0; k<3; k++)
{
s1[dx] = m2d[j*c+k]; //it so happens that we can do both slices in 1 loop
s2[dx++] = m2d[j*c+k+3];
}
}
//proof / printout
for(int j = 0; j < 18; j++)
{
cout<< s1[j] <<",";
if((j+1)%3==0) cout << endl;
}
cout <<"------------"<<endl;
for(int j = 0; j < 18; j++)
{
cout<< s2[j] <<",";
if((j+1)%3==0) cout << endl;
}
}
|