Been struggling with this a few times now and have inserted some additional printf commands to try and understand what's going on with the variables used to control my loops (please see instructions, code and output in screenshot below).

Think the issue is with the set-up of the innermost loop on line 20. Have fiddled about a bit but can't figure it out.

Any thoughts or suggestions appreciated.

Many thanks!


Code for nested loops to print right-aligned pyramid

1 Answer 1


Nesting loops to a level of three makes little sense for iterating 2D structures.

I think you have to move your innermost loop out, directly in front of the loop it's currently in, so that you have two loops at the same nesting level inside the outer loop.

  • Should be printing the # inside the last loop as well. Also, the starting values of the inner loop counters are off. Commented May 26, 2019 at 18:40
  • @counterterror Not sure what you mean. If I make the b loop the second inner loop now containing only the printf("#");, but no other nested loop, the counter should work. The now first inner loop with the c variable obviously needs adjustment (can't use b variable).
    – Blauelf
    Commented May 26, 2019 at 22:19
  • Sorted! Thanks so much @Blauelf! Commented May 16, 2020 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .