# Thread: how to print out these structures??? plz help

1. ## how to print out these structures??? plz help

friends help me how to print out these structures using loops.. i'm unable to find any solution.. it is not necessary to give me the entire code, if u can only explain me the solution , it'll also b ok..

plzz help me printing out these outputs using loops.. thanx everyone..

2. To understand the problem better, get a piece of graph paper, and start with your last problem. (You can make graph paper columns just using regular paper, just add the column lines in with a pencil and straight edge.)

Now imagine your pencil is the print head (or cursor position on the screen), and you can only move the pencil point to the right, and then down once, at the end of the row.

Never to the left, or upward.

Now print out the last diagram, SLOWLY. Note how you are doing it, at a very simple level. The logic you are using to do this, is the very same logic that your computer can use, once you make it simple enough.

Do that exercise with the pencil nice and slowly a few times, and your understanding of the problem, will deepen. The "lightbulb" will turn on!

In general, using two nested loops is a good idea. Use the outer for loop to control the row counter, and the inner for loop to handle everything else.

Code:
```for(each row in the diagram) {
for(each column in the row you're printing atm) {
}
}```
Naturally, you're going to increment a row and col variable in each for loop, and use if statements probably, as part of the logic code.

Programming involves a lot of critical thinking and problem solving, so this is a great exercise to start with.

3. adak.. i'm goin to try wit ur advice.. i'll ask u again if i face some problem.. thanxxx for xplaining ...

4. Originally Posted by Rbsupercool
adak.. i'm goin to try wit ur advice.. i'll ask u again if i face some problem.. thanxxx for xplaining ...
What, you are on the phone and sending sms?

5. @adak your advice really worked... i experimented a little bit with that graph nd solved the last problem.. it feels so good..thank u very much for ur advice.. this is what i've done..
Code:
```#include <stdio.h>

int main()
{
int i,a ;
for(i=1;i<=5;i++)
{
int j=1;

while(j<= 5-i)
{
printf(" ");
j++;
}

for(a=1;a<=i;a++)
{
printf("%d ",i);
}
printf("\n");

}
return 0;
}```
last problem solved.. it was easiest though.. the first three problems are yet to solve.. any advice from anyone will help me..

6. Once you get into these things, the solution goes a lot faster.

#1 - look at the vertical columns the digits all line up in.

Code:
```░░1
2░░░3
etc.```
Three spaces maybe, between the digits in the same row? Eazy-peazey!

Repeat the graph paper exercise if you need it, with every diagram. It gets much faster with practice.