# Thread: a little trouble with for loops

1. ## a little trouble with for loops

Hey all, I'm having a little trouble with a homework problem. Here it is:
Write a problem that creates the following pattern:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Now I know that this will involve nested for loops, but every attempt I've made gives me results like:
999999999
888888888
777777777
666666666
555555555
444444444
333333333
222222222
111111111

Any ideas?

2. make the second loop depend on how far the first loop's gone and make it count from 1-9 (and counting down) instead of just filling the array with which value the first loop was on.

3. Code:
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{
/*Local Definitions*/
int row;
int col;
int limit;

/*Statements*/
limit = 9;
for (row = 1; row < limit; row++)
for (col = 1; col < limit; col--)
printf("%d", row);
printf("\n");

system("PAUSE");
return 0;
}```
this is what I have based on that...it's wrong , I know. Help.
melee

4. to clerify my first post I didn't mean that the code should be counting down using -- I ment that is should shorten how high the values would be able to go, sorry if if it caused you any trouble.

something like

Code:
```for (i=0:i<10;i++)
{
for (j=0;j<10-i;j++)
{
/*stuff*/
}
/*stuff*/
}```

5. Hi, try it likle this, it should produce the output as you're asked for.

Code:
```#include <stdio.h>

int main(void)
{
int y=0, z=0;

for(y=9; y>0; y--)
{
for(z=1; z<y+1; z++)
{

fprintf(stdout,"%d",z); /* print the numbers */

}  /* end of nested for loop */

printf(stdout,"\n");   /* print the new line */
}   /* end of outer loop */
return 1;
}```

6. Any occasion I can use this code makes for a good day!
Code:
```void O_Oy( char *o_o, int o_O )
{
char V_V[BUFSIZ]="%s\n";
char T_T[BUFSIZ]="%%[^%s]";
char v_v[BUFSIZ]={0};
char x_x[BUFSIZ]={0};

while( o_O -- )
{
sprintf( v_v, T_T, o_o + o_O + 1  );
sscanf( o_o, v_v, x_x );
printf( V_V, x_x );
}
}

int main( void )
{
char o_o[] = "1234567890";

O_Oy( o_o, 0x9 );

return 0;
}```

Quzah.

7. Quzah, I love that code...unfortunately, it is completely over my head at the moment. However, I'm saving it...and one day...when I'm a grown up programmer, I'll understand it...hopefully. Thanks!!

micklarko, shogun: Thank you ever so much. Shogun's code worked excellently!

melee