Need help - Nested Loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rkc
    New Member
    • Oct 2006
    • 2

    Need help - Nested Loops

    Hi,

    I need to design the following pattern using just the 'for' and the 'if, else' statement. Please provide some help.. thanks in advance:

    **********
    !*********
    !!********
    !!!*******
    !!!!******
    !!!!!*****
    !!!!!!****
    !!!!!!!***
    !!!!!!!!**
    !!!!!!!!!*

    The editor doesnt allow me to enter a space, so please replace ! with a space.

    any help appreciated, thanks in advance.
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    Code:
    int N = 10;
    for(int i = 0; i < N; i++)
    {
      string(i,' ');
      string(N-i,'*');
    }

    Comment

    • ltgbau
      New Member
      • Sep 2006
      • 41

      #3
      Code:
      for(int i=0; i<10; i++)
      {
           for(int j=0; j<i; j++)
           {
                cout<<" ";
           }
           for(int j=i; j<10; j++)
           {
                cout<<"*";
           }
           cout<<endl;
      }
      :D :D :D this will create a triangle from '*' characters.....

      Comment

      • dynamicleo
        New Member
        • Oct 2006
        • 14

        #4
        Code:
        for (int i = 1; i <= 10; i++) {
        
            for (int j = 1; j <= 10; j++)
                cout<< ( j < i ? ' ' : '*' );
        
            cout<< '\n';
        }

        Comment

        Working...