haha you're reading C primer Plus? I just seen that the other day as I was going through it. Why don't you follow the example in the book?
Find the pattern:
it always prints out the 6th then works its way backward off the 6th.
Code:
first time,
print 6th
start over
print 6th,5th
starts over,
print 6th, 5th,4th,
starts over
repeats until end point, is what? 6
start count needs to always be set back to start point, then another count to and check for where you want to end again, then kick it out of inner loop, increment some number var start again. or increment then kick out ... either way you're going to need more var to keep track and maybe some if statements and take a break too while you're at it.
that is what I'd try until I got it right.
off the top of my head:
Code:
int a = 0,b = 1, c = 1, d = 6;
for ( a = 0; a < 6; a++)
{ d = 6;
for ( b = 1; b <= c; b++)
{
printf(" %d \n", --d);
}
c++;
}
outer loop controls the up to 6 times
inner loop count check gets set to one more each pass
d gets printed , but that part still does not look right.
but it might just work with a little fiddling.