Displaying an array

Hello guys!
So I encountered this problem of not knowing how to display my random numbers from an array. The display should have 6 columns and I don’t know how about the rows. It is up to the user to enter amount of numbers in the array. Then, rand() will generate the numbers and display them in 6 columns like that (IF USER ENTERED 26 NUMBERS)

1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1

I know how to generate the numbers and all that, my problem is only in displaying 1d array in that format. (the output has to compatible with other numbers entered as well not only 26) Any help or pointing in the right direction would be much appreciated.
Thanks,
uszy 123345.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>

int main()
{
    std::size_t columns = 6;

    std::vector<int> v(26, 1);

    for (unsigned i = 0; i < v.size(); ++i)
    {
        std::cout << v[i];

        if ((i+1) % columns == 0)
        {
            std::cout << '\n';
        }
    }

    std::cout << '\n';

}
Last edited on
Topic archived. No new replies allowed.