Hey, I'm new here. Just getting into c++ programming and saw some great resources on this site.

I figured out how to print a fully random array, but I need help printing an array like this.

1 2 3
2 3 1
3 1 2

It could be any three numbers, it's sort of like a sudoku puzzle. basically I need to pick 3 random numbers and print them in a sequence where they will not repeat themselves.

Recommended Answers

All 2 Replies

Create all permutations and shuffle them. Read about std::next_permutation and std::random_shuffle.

You have :

1 2 3
2 3 1
3 1 2

Think of it as a variable :

a b c
b c a
c a b

1) you can see that they are rotated to the left.
a b c //original
b c a //rotated to the left and is circular
c a b //rotated to the left and is circular


But an easier solution is to get input >> a>> b >> c;
and create a matrix ,
int Matrix[9] = { a , b , c , b, c, a , c , a , b }

and print it out in columns of 3.

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.