hi to all i nid help

This is a discussion on hi to all i nid help within the C++ Programming forums, part of the General Programming Boards category; hi to all i nid help..i nid to create a program using for statement and draw its equivalent pls help ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    4

    hi to all i nid help

    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
    Last edited by jezzie; 08-16-2010 at 11:19 PM. Reason: wrong grammar

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    4

    Angry

    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;
    }
    Last edited by jezzie; 08-16-2010 at 11:37 PM. Reason: wrong numbers

  3. #3
    Registered User
    Join Date
    Jul 2010
    Location
    Oklahoma
    Posts
    107
    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

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    4

    Wink

    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..

  5. #5
    Registered User
    Join Date
    Jul 2010
    Location
    Oklahoma
    Posts
    107
    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

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    4
    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....

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    "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?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    Quote Originally Posted by iMalc View Post
    Your compiler doesn't accept misspellings and bad syntax, so why should we?
    Great one! I'm going to add that one to my signature.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. TBADDBITMAP nID member
    By jmd15 in forum Windows Programming
    Replies: 2
    Last Post: 10-03-2005, 02:29 PM
  3. Dialog Issues in VC++
    By Frustrated in forum Windows Programming
    Replies: 1
    Last Post: 09-26-2001, 11:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21