How to flip a number

so if we have a loop like that

int i-0
1
2
3
4
5
6
while(i<5)
{
Sum= i + 2
i++
cout << sum << endl;
}


output will be
2 3 4 5 6


now what if i want to place the numbers in the opposite way

6 5 4 3 2. how can I do that ?
closed account (Dy7SLyTq)
put it in a container and just reverse it
@DTScode
what is a container ?
closed account (Dy7SLyTq)
vector, list, array, map, queue, array (built-in), set, stack, etc
@DTScode


so something like that instead ?

while(i<5)
{
Sum[i1]= i + 2
i++;
i1++;
cout << sum[i] << endl;
}
for (i=5; i>=0; i--)
cout << sum[i1] << endl;
Last edited on
It is enough to change only one statement

1
2
3
4
5
6
7
i = 0;
while(i<5)
{
Sum= 6 - i;
i++;
cout << sum << endl;
}
Topic archived. No new replies allowed.