Jezzie,
Alright, so right now you have (after numbering the lines with cat):
Code:
1 #include,stdio.h>
2 #include<stdlib.
3 int main
4 {
5 int x,y;
6 for(x=1;x<=5;x++)
7 {
8 for(y=1;y<=x;y++)
9 {
10 printf("%d",y);
11 }
12 printf("\n");
13 }
14 }
15 system("pause");
16 return 0;
17 }
So after reading the faq, posting guidelines and fixing:
Line 1: replace ',' with '<'
Line 2: append 'h>'
Line 3: the parenthesis for the main definition
The indention in general, now I've got:
Code:
1 #include<stdio.h>
2 #include<stdlib.h>
3
4 int main
5 {
6 int x,y;
7
8 for(x=1;x<=5;x++)
9 {
10 for(y=1;y<=x;y++)
11 {
12 printf("%d",y);
13 }
14 printf("\n");
15 }
16 printf("\n");
17
18 system("pause");
19 return 0;
20 }
Now it compiles, and the output looks like:
Code:
1 1
2 12
3 123
4 1234
5 12345
6
You've identified that you are missing the second set of numbers, and that these are not the correct sequence of numbers. That is, for the second set something like:
Code:
12345
2345
345
45
5
Let's start by working out that second set of numbers. How about a loop that runs five times (once for each line of numbers), to start with:
Code:
for( x = 1; 5 >= x; x++ )
{
// print a line of numbers
printf( "\n" );
}
printf( "\n" );
The problem then becomes, how to formulate the current line of numbers with only the current line number (x) available for control?
Another loop perhaps?
Code:
for( y = 1; y <= 5; y++ )
{
printf( "%d", y );
}
That would print the entire sequence every time it ran though...it would look like:
Code:
1
12
123
1234
12345
12345
12345
12345
12345
12345
Not what the problem statement requires. So there must be a conditional of which one may take advantage, for example in the first loop the constraint (line 10 from the 'clean' segment) was rather intuitive, namely 'y <= x.' But this time the value for y wouldn't include the latter values in the sequence if we apply a constraint to the loop control. That is, we need that the entire sequence be generated for every line, right? So we change the timing about when to print on the flow control...thus:
Code:
for( y = 1; y <= 5; y++ ) // print one line of numbers
{
if( y >= x )
{
printf( "%d", y );
}
}
That should get the second set of numbers printed properly, please assemble some guesses about how to get the first set of them. It should be easier now that you have something that compiles. Please respond with your results. And check out the posting guidelines...some code tags would have been great.
Best Regards,
New Ink -- Henry