Hello,

I have this matrix:

0 0 1 0
0 0 1 0
1 1 1 0
0 1 0 0

and I need to print out the block with the coords: (2,1) so in this case:
1 0
1 0

I have tried this:

for(int i=minRow; (i < 2); i++)
    {
        for(int j=minCol; (j < 2); j++)
        {
            cout << matrix1[i*2+j] << ' ';
        }
        cout << endl;
    }

As well as this:

for(int i=minRow; (i < 4); i++)
    {
        for(int j=minCol; (j < 4); j++)
        {
            cout << matrix1[i*4+j] << ' ';
        }
        cout << endl;
    }

But it doesn't work, does anyone have any suggestions? Thanks :)

HI,

I didn't understand your question properly... as per my understanding

coords:(col,row)
(2,1) :
1 0
1 0
(2,2):
1 0
1 0
1 0
(1,2):
0 1 0
0 1 0
1 1 0
if i am going in right direction the you can check with the below code.

#include<iostream>
using namespace std;
int main()
{
        int matrix[][4]={{0,0,1,0},\
                        {0,0,1,0},\
                        {1,1,1,0},\
                        {0,1,0,0}};
        int minColumn=0;
        int minRow=0;
        cout << "Enter minColumn:";
        cin >> minColumn;
        cout << "Enter minRow:";
        cin >> minRow;
        for(int i=0;i<=minRow;i++)
        {
                for(int j=minColumn;j<4;j++)
                {
                        cout << matrix[i][j] << " ";
                }
                cout << endl;
        }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.