Thread: finding difficulties

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    23

    Question finding difficulties

    how do we write a for loop which will produce the following output using two nested for loops
    1
    22
    333
    4444
    55555

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    This is a simple idea. Have you tried thinking about double for loops? You will need it here. I don't want to tell you the solution, because it is better to learn.
    Code:
    for(...;...;...) {
       for(...;...;...) {
          // some print statement
       }
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    My question is what the hell have you been up to in the past week that you ask the same question with the same lack of effort?
    need help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    23

    Question try one

    we'll i have tried this one but it seems that there is too many errors
    Code:
    #include <iostream>
    int j,i,max;
    main()
    {
    for (i=1;i<max;i++)
    {
       for(j=i;j>0;j--)
          { 
          printf("%d",i);.
          }
          printf("\n",);
    }
    
    	system("pause");
    
    	
    }

  5. #5
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    This must be a troll.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Perhaps you should practice getting ONE loop to compile first, before trying two.

    Say output
    1
    2
    3
    4
    5

    Surely you could do that?

    Maybe?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User BuzzBuzz's Avatar
    Join Date
    Feb 2009
    Posts
    89
    Quote Originally Posted by luke luvevou View Post
    we'll i have tried this one but it seems that there is too many errors
    Code:
    #include <iostream>
    int j,i,max;
    main()
    {
    for (i=1;i<max;i++)
    {
       for(j=i;j>0;j--)
          { 
          printf("%d",i);.
          }
          printf("\n",);
    }
    
    	system("pause");
    
    	
    }
    If you're supposed to be C++ then copying and pasting someone else's program is not going to earn you any brownie points with whoever your educator is - especially when it is not completely C++ and does not work.

    Now to echo Salem, what have YOU done to try and solve the problem (trawling the Internet for 'close but not cigars' code does not count) - have YOU written any code yourself?
    Any help I give may be classified as:
    The Blind leading the Blind...
    Currently working through:
    "C++ Primer Plus"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Finding divisors
    By xbusterx in forum C++ Programming
    Replies: 20
    Last Post: 10-04-2008, 08:08 PM
  3. Finding primes
    By scwizzo in forum C++ Programming
    Replies: 11
    Last Post: 09-10-2008, 06:15 PM
  4. Finding primes
    By starripper in forum C++ Programming
    Replies: 19
    Last Post: 01-14-2006, 04:17 PM
  5. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM