Outputting Values in Selective Array Indexes

Hi All, I need your help in working out this problem. I want to print that desired output but i'm struggling with the logic.

[1000] [1001] [1002] [ * ] [1004] [1005]
[1006] [ * ] [1008] [1009][1010] [ * ]
[1012] [1011] [1014] [ * ] [1016] [1016]
[1018] [ * ] [1020] [1021][1022] [ * ]
[1024] [1025] [1026] [ * ] [1028] [1029]
[1030] [ * ] [1031] [1033][1034] [ * ]

This is what i have so far.

for(row= 0; row< 6; row++ )
{
cout<<" "<<endl;
for(column = 0; column < 6; column++)
{

table[row][column] = count;
cout<<"["<<table[row][column]<<"]";
count++;
}
}

Output:

[1000][1001][1002][1003][1004][1005]
[1006][1007][1008][1009][1010][1011]
[1012][1013][1014][1015][1016][1017]
[1018][1019][1020][1021][1022][1023]
[1024][1025][1026][1027][1028][1029]
[1030][1031][1032][1033][1034][1035]

I want to be able to manipulate every 4 index.
e.g. the first index is table[0][3] = *, then table[1][1]=*, then table[1][6]=* etc.

Would appreciate your support on this,

Thanks
What do you mean? Can you post your full code?
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>

int main()
{
    constexpr std::size_t NROWS = 6 ;
    constexpr std::size_t NCOLS = 6 ;

    int array[NROWS][NCOLS] ;
    int n = 1000 ;
    for( auto& row : array ) for( int& v : row ) v = n++ ;

    const std::size_t STRIDE = 4 ; // get to every every fourth item

    {
        // using range-based loops and a count
        std::size_t cnt = 0 ;
        for( const auto& row : array )
        {
            for( int v : row )
            {
                ++cnt ;
                if( cnt%STRIDE == 0 ) std::cout << "[  * ] " ;
                else std::cout << '[' << v << "] " ;
            }
            std::cout << '\n' ;
        }
    }

    std::cout << "--------------------------------------------\n" ;

    {
        // using classical for loops and a count
        std::size_t cnt = 0 ;
        for( std::size_t row = 0 ; row < NROWS ; ++row )
        {
            for( std::size_t col = 0 ; col < NCOLS ; ++col )
            {
                ++cnt ;
                if( cnt%STRIDE == 0 ) std::cout << "[  * ] " ;
                else std::cout << '[' << array[row][col] << "] " ;
            }
            std::cout << '\n' ;
        }
    }

    std::cout << "--------------------------------------------\n" ;

    {
        // using classical for loops, compute from indices
        for( std::size_t row = 0 ; row < NROWS ; ++row )
        {
            for( std::size_t col = 0 ; col < NCOLS ; ++col )
            {
                if( ( row*NCOLS + col ) % STRIDE == (STRIDE-1) ) std::cout << "[  * ] " ;
                else std::cout << '[' << array[row][col] << "] " ;
            }
            std::cout << '\n' ;
        }
    }
}

http://coliru.stacked-crooked.com/a/4466579a5323426d
Topic archived. No new replies allowed.