I have trouble with for
If n=3, these two for loops gives me answer like:
0 2
0 1
0 0
1 2
1 1
1 0
2 2
2 1
2 0
And I want answer like this(I will use it in double array):
0 2
1 1
2 0
1 2 3 4 5 6 7
|
for(int v=0; v<n; v++)
{
for(int k=n-1; k>-1; k--)
{
cout<<v<<" "<<k<<endl;
}
}
|
Thanks.
For one, this would be a great use of declaring the variable that increments outside of the for loop entirely. Let me see...
1 2 3 4 5 6 7 8
|
int k = n-1;
for(int v = 0; v < n; v++)
for(;k > -1;)
{
cout << v << " " << k << endl;
k--;
break;
}
|
That should get you the result you want. Well, should. If not, tell me the output and I'll try to find what I wrote incorrectly.
Last edited on
Thank you Ispil. The code works perfectly.
Topic archived. No new replies allowed.