Originally Posted by
kermit
Whats up with the non-standard header and function call?
More importantly, what's up with doing the whole thing for them? If you're going to do it, do something interesting with it:
Code:
for( i = 0; i < k; i += printf("\n") )
for( j = 0; j < i+1; j += printf("%d",i+1) );
This works because the code is restricted to just 1-9. (The other code posted will also break if you input higher than 9.) Naturally, there are more ways to do this. Since you already know that you can never go past nine...
Code:
char *buf[9] = {
"1",
"22",
"333",
"4444",
"55555",
"666666",
"7777777",
"88888888",
"999999999" };
for( i = 0; i < k; i++ )
printf("%s\n", buf[i] );
Or perhaps...
Code:
char buf[]={"1\n22\n333\n4444\n55555\n666666\n7777777\n88888888\n999999999\n"};
puts( buf );
[preview]
There's an interesting bug with this forum. It seems you cannot make the above line. It doesn't work. Oh, sure, you see it. But the way you see it is not the way the actual line is. There are no spaces in the true above line. This forum apparently inserts whitespace after the eights. I have no idea why, nor have I found a way around this. Splitting this line so that the quotation marks are the first and last characters on the line doesn't change the forum-generated visual. There is no way to get this line to actually appear the way it really does using [code] tags. It is also interesting to note, that if I use [quote] tags, it inserts one space, where as the [code] tags insert what appears to be two spaces.
At any rate, assume there are no spaces in the above char line.
[/preview]
You could even shorten the above to a string literal, and puts or printf it directly.
Or you could always do:
Code:
for( i = 0; i < k; i++, putchar('\n') )
for( j = 0; j < i+1; j++, putchar( '1'+i ) );
You know, something amusing that the instructor will appreciate.
Quzah.