How to reverse the loop?

Write a C++ program to generate and print out the following series (using a single for loop): 10 8 6 4 2 0 2 4 6 8 10



//This prints (10 8 6 4 2 0)
for (c1 = 10; c1 > 0; c1 -= 2)
{
cout << setw(4) << c1;
}

how will I inverse it ? (2 4 6 8 10) in the same loop
Last edited on
1
2
3
4
5
6

for(c1=10;c1>=(-10);c1-=2)//extending loop to -10
{
int j=abs(c1); //just taking the absolute value.
cout<<setw(4)<<j;  //if you use c1 here instead of j you will get an infinite loop
}


I hope this helps :D

ps: please use code tags
Topic archived. No new replies allowed.