Print Matrix

0

When I print this matrix, it should go vertical, as the 1s come out, but I get everything in a straight line. But if after cout << char(254); I put a endl I get spaces between each character and not together.

if (x == 1) {
    int figuras_1[4][4]{
    { 0, 1, 0, 0 },
    { 0, 1, 0, 0 },
    { 0, 1, 0, 0 },
    { 0, 1, 0, 0 }

    };
    for (int f = 0; f < 4; f++) {
        //cout << endl;
        for (int c = 0; c < 4; c++) {
            if (figuras_1[f][c] == 1) {
                cout << char(254);
            }
        } 
    }
}
    
asked by Francesco Bassino 08.11.2018 в 01:12
source

1 answer

1

Try doing it this way. They print one below the other, without jumping lines.

if (x == 1) {
    int figuras_1[4][4]{
    { 0, 1, 0, 0 },
    { 0, 1, 0, 0 },
    { 0, 1, 0, 0 },
    { 0, 1, 0, 0 }

    };
        for (int f = 0; f < 4; f++) {
            for (int c = 0; c < 4; c++) {
            if (figuras_1[f][c] == 1) {
                if(f>0)
                    cout << "\n";
                cout <<  static_cast<char>(254) ;
               }
            } 

        }
    }

Result:

    
answered by 08.11.2018 / 01:57
source