DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5

Thread: For Loops

  1. #1
    Christy Guest

    For Loops


    Help!!!!!

    How can nested for loops be used to print numbers in this format?

    1
    23
    345
    4567

    ANY help will be greatly appreciated!!




  2. #2
    Mark C Guest

    Re: For Loops


    This is a good logic problem...figure it out!

    You'll find that you'll get more assistance if
    you at least show what you have so far...

    "Christy" <sprynter0@yahoo.com> wrote:
    >
    >Help!!!!!
    >
    >How can nested for loops be used to print numbers in this format?
    >
    >1
    >23
    >345
    >4567
    >
    >ANY help will be greatly appreciated!!
    >
    >
    >



  3. #3
    christy Guest

    Re: For Loops


    //
    //

    #include <iostream>
    #include <conio.h>

    int n;

    Yeah, I agree...what I've got so far might be helpful..thanks for the tip...

    int main()
    {
    for ( int a = 1 ; a <= 1; a++ ){
    cout << a <<endl;
    for ( int a = 1; a <= 2; a++ ) {
    cout<< a << endl; }
    for ( int a = 1; a <= 3; a++ )
    cout << a << endl;
    }
    }getche();
    return 0;

    }
    this is the output I'm trying to obtain
    1
    23"Mark C" <mdcashion@hotmail.com> wrote:
    >
    >This is a good logic problem...figure it out!
    >
    >You'll find that you'll get more assistance if
    >you at least show what you have so far...
    >
    >"Christy" <sprynter0@yahoo.com> wrote:
    >>
    >>Help!!!!!
    >>
    >>How can nested for loops be used to print numbers in this format?
    >>
    >>1
    >>23
    >>345
    >>4567
    >>
    >>ANY help will be greatly appreciated!!
    >>
    >>
    >>

    >



  4. #4
    Ken Guest

    Re: For Loops


    Here is something you might want to try.
    int j = 2, total = 5, count = 0;

    for (int i = 1; i < total; i++)
    {
    cout << i;
    count = 0;
    for (int ii = 2; ii < j; ii++)
    cout << (j + count++);

    j++;
    cout << endl;
    }

    Basically you need a loop for the column and another loop for rows. You
    just need to keep track of how you increment the values.

    Later
    Ken

    "christy" <sprynter0@yahoo.com> wrote:
    >
    >//
    >//
    >
    >#include <iostream>
    >#include <conio.h>
    >
    >int n;
    >
    >Yeah, I agree...what I've got so far might be helpful..thanks for the tip...
    >
    >int main()
    >{
    > for ( int a = 1 ; a <= 1; a++ ){
    > cout << a <<endl;
    > for ( int a = 1; a <= 2; a++ ) {
    > cout<< a << endl; }
    > for ( int a = 1; a <= 3; a++ )
    > cout << a << endl;
    > }
    > }getche();
    > return 0;
    >
    >}
    >this is the output I'm trying to obtain
    >1
    >23"Mark C" <mdcashion@hotmail.com> wrote:
    >>
    >>This is a good logic problem...figure it out!
    >>
    >>You'll find that you'll get more assistance if
    >>you at least show what you have so far...
    >>
    >>"Christy" <sprynter0@yahoo.com> wrote:
    >>>
    >>>Help!!!!!
    >>>
    >>>How can nested for loops be used to print numbers in this format?
    >>>
    >>>1
    >>>23
    >>>345
    >>>4567
    >>>
    >>>ANY help will be greatly appreciated!!
    >>>
    >>>
    >>>

    >>

    >



  5. #5
    David Guest

    Re: For Loops


    Try this out,

    #include <iostream>

    using std::cout;
    using std::endl;

    int main()
    {
    for (int row = 1 ; row <= 4; ++row)
    {
    for (int column = 0; column < row; ++column)
    {
    cout << (row + column);
    }

    cout << endl;
    }

    return 0;
    }




    "Christy" <sprynter0@yahoo.com> wrote:
    >
    >Help!!!!!
    >
    >How can nested for loops be used to print numbers in this format?
    >
    >1
    >23
    >345
    >4567
    >
    >ANY help will be greatly appreciated!!
    >
    >
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links