hi to all i nid help..i nid to create a program using for statement and draw its equivalent pls help me tnx..
5
45
345
2345
12345
12345
2345
345
45
5
Printable View
hi to all i nid help..i nid to create a program using for statement and draw its equivalent pls help me tnx..
5
45
345
2345
12345
12345
2345
345
45
5
pls help..what to change to display the ff above..
#include,stdio.h>
#include<stdlib.
int main
{
int x,y;
for(x=1;x<=5;x++)
{
for(y=1;y<=x;y++)
{
printf("%d",y);
}
printf("\n");
}
}
system("pause");
return 0;
}
Jezzie,
Alright, so right now you have (after numbering the lines with cat):
So after reading the faq, posting guidelines and fixing: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 }
Line 1: replace ',' with '<'
Line 2: append 'h>'
Line 3: the parenthesis for the main definition
The indention in general, now I've got:
Now it compiles, and the output looks like: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 }
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:1 1
2 12
3 123
4 1234
5 12345
6
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:12345
2345
345
45
5
The problem then becomes, how to formulate the current line of numbers with only the current line number (x) available for control?Code:for( x = 1; 5 >= x; x++ )
{
// print a line of numbers
printf( "\n" );
}
printf( "\n" );
Another loop perhaps?
That would print the entire sequence every time it ran though...it would look like:Code:for( y = 1; y <= 5; y++ )
{
printf( "%d", y );
}
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:1
12
123
1234
12345
12345
12345
12345
12345
12345
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.Code:for( y = 1; y <= 5; y++ ) // print one line of numbers
{
if( y >= x )
{
printf( "%d", y );
}
}
Best Regards,
New Ink -- Henry
New Ink-- Henry
i really don't get it..but its okay tnx anyway..its our midterm exam tomorrow and thats our topic gosh why it was so hard....but im still gonna try to get it!!tnx again..
Jezzie,
Most of it is there...you can do it. The first loop is a little different, but I'll give you a hint: 5-x....
Best Regards,
New Ink -- Henry
omg! i got the 2nd, im trying to figure out the 1st one..i knew i can do it..tnx a lot HENRY..its the easiest anyway among the 2 ryt....
"omg plz giv me teh codez k thx bye" etc, is not acceptable language for a web forum such as this. You will find very few people help you if you keep that up.
Your compiler doesn't accept misspellings and bad syntax, so why should we?