The idea is this:
Your have a position for each element of v (9 in your case):
- - - - - - - - -
Each position can hold three different values (-1 | 0 | 1) and then the total number of combinations is equal to 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 = 3^9.
To generate such combinations only simulate this process, for example with for loops, e.g. for three positions:
values[] = {-1, 0, 1};
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
for (k = 0; k < 3; k++)
print values[i], values[j], values[k]
In your case you need nine nested loops! An easier implementation will involve recursion but its sometimes more complicated to understand. Here is the idea anyway:
values[] = {-1, 0, 1};
void generate(int position)
{
if (position == 0) {
println();
return;
}
for (int i = 0; i < 3; i++) {
print(values[i], ", ");
generate(position - 1);
}
}
// call the function with
generate(9);
This another answer explains a little more how a recursive generator works.