### For loop

i want to create a program that displays this exact numbers:
10
109
1098
10987

i want to see the code for this for me to understand loop. i just can't figure out how it is done.
It is done the following way

10

10 9

10 98

10 987

So all what you need to do is in fact to display

9
98
987
The straitforward approach is for example

 ``123456`` ``````for ( size_t i = 0; i < 4; i++ ) { std::cout << 10; for ( size_t j = 9; j > 9 - i; j-- ) std::cout << j; std::cout << std::endl; }``````

There are many ways to do the task. For example

 ``123456`` ``````std::string s( "10" ); for ( size_t i = 10; i != 6; s += char( --i + '0' ) ) { std::cout << s << std::endl; }``````
This is it in its most basic form.

 ``123456789`` ``````for (size_t nMin=10; nMin>0; nMin--) { for (size_t nNum=10; nNum>=nMin; nNum--) { std::cout << nNum; } std::cout << std::endl; } ``````
i typed up a guide for loops that breaks down the concepts and each type with example codes. iIf you would like me to email it to you just pm me your email.
Enjoy!:)

 ``12345678910111213141516171819202122232425262728`` ``````#include int main() { while ( true ) { std::cout << "Enter a non-negative number (0 - exit): "; size_t n; std::cin >> n; if ( !n ) break; std::cout << std::endl; for ( size_t i = 0; i < n; i++ ) { const size_t base = 10; size_t j = 0; do { std::cout << base - j % base; } while ( j++ != i ); std::cout << std::endl; } } }``````
the straightforward approach youve stated is what im looking for. thanks :D
Topic archived. No new replies allowed.