Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello every one how can i split an array into blocks.For example Given an array of size 4x4 divide the array by blocks of 2x2 and then the size of the array is 4x4 so there will be four blocks of 2x2.

In this case block size is 2;

C++
             Block 1      Block2
0 1 0 0       0 1         0 0
1 1 1 0 - >   1 1         1 0
0 0 0 0 - >
1 1 0 0       Block 3      Block4
              0 0          0 0
              1 1          0 0

I want something like this. Any help would be appreciated

What I have tried:

Actually i could not make it because i couldn't have find any idea
Posted
Updated 14-Jun-18 20:10pm

1 solution

How about:

C++
int block[4][4] =
{
    { 0,1,0,0 },
    { 1,1,1,0 },
    { 0,0,0,0 },
    { 1,1,0,0 }
};

int block1[2][2];
int block2[2][2];
int block3[2][2];
int block4[2][2];

for (int i = 0; i < 2; i++)
{
    for (int j = 0; j < 2; j++)
    {
        block1[i][j] = block[i][j];
        block2[i][j] = block[i][j+2];
        block3[i][j] = block[i+2][j];
        block4[i][j] = block[i+2][j+2];
    }
}
 
Share this answer
 
Comments
Sukerbek 16-Jun-18 2:53am    
Thank you so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900