Modified Output in Nested-Loop Statement Help

Good day to everyone. I have a concern regarding the code and the output below.
We need to modify it by reversely copying the actual output below. Can someone lend me help with this also?

Actual Output:
1
12
123
1234
12345
123456
1234567
12345678

What the output should be like:
12345678
1234567
123456
12345
1234
123
12
1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
int i=1,j;
while (i <=8)
{
j = 1;
while (j <=1) {
cout << j;
j++;
}
cout << endl;
i++;

}
getch ();
return 0;
}

Last edited on
Maybe like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
    for (int i = 9; i > 1; --i)
    {
        for (int j = 1; j < i; ++j)
            cout << j;
        cout << "\n";
    }
}

Output:
12345678
1234567
123456
12345
1234
123
12
1


https://onlinegdb.com/t5n2Wqgov
For an alternative take:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <numeric>
#include <string>

int main() {
	constexpr size_t noRows {8};

	for (size_t i = noRows; i > 0; --i) {
		std::string row(i, 0);

		std::iota(row.begin(), row.end(), '1');
		std::cout << row << '\n';
	}
}



12345678
1234567
123456
12345
1234
123
12
1

Thanks, men I appreciate it
Topic archived. No new replies allowed.