Why do you think it would just print j once? j is inside a loop from 1 to i.
So when i is 1, j will loop from 1 to 1, and print 1
Then it will print a new line
Then when i is 2, j will loop from 1 to 2, and print 12
Then it will print a new line
And so on through 10.
Maybe what you're missing is the fact that in C, when you have a for loop or if statement, if there are no {}, it will include everything up to the next ; as part of the block.
So:
Code:
for(j=1;j<=i;j++)
printf("%d",j);
Code:
for(j=1;j<=i;j++) printf("%d",j);
Code:
for(j=1;j<=i;j++) {
printf("%d",j);
}
are all equivalent.