### A Nested Loop To Produce a Pattern?

Hi.

I need to write a *Nested Loop* to produce the following pattern:

 1234 3 34 345 3456

Can anybody give me a hand?

I could kind of guess that we should do something along these lines:

 123456 for (int a = 3; a <= 6; a++) { for (int b = a; b <= 3-(a-2)+1; b++) { cout << b; } cout << endl; }

But I'm not really sure how.

Thank you very much in advance :)
We don't normally like to do homework. You were close, but you put too much in the inner for loop if statment. Something like this might work better. Sometimes you just need to sit back and re-write your code while taking a different approach. There is ALWAYS a solution and something like this should be simple.

 123456 for (int a = 0; a < 4; a++) { for (int b = 0; b < a+1; b++) { cout << b + 3; } cout << endl; }
Last edited on
 1234567891011121314 #include #include void main() { clrscr(); for(int i=4;i<8;i++) { for(int j=3;j
Last edited on
Thanks a lot for the answers!

I totally understood how this works. You guys were helpful.
Topic archived. No new replies allowed.