Help! Nested Loop

I need help creating a nested loop (it can be a while loop or a for loop) that results in this paturn:

**
****
******
********
**********
************
**************
****************

I don't know where to start.

If it is the code u want try this


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream.h>
#include<conio.h>  // non standard libary function for clrscr() and getch()

void main()
         {
            clrscr();
            int i,j;
           for(i=0;i<=10;++i)   // first loop
                   {
                       for(j=0;j<=i;++j) // second nested loop
                      cout<<"*";
                     cout<<"\n";
                   }
                 getch();
           }


I guess it is correct...
As you may know conio is a non standard h file so please use any alternate for clrscr() and getch()
cheers,
cyber dude


@cyberdude

iostream.h is also nonstandard. Just delete the ".h" at the end to use the correct, standard iostream header file.
Also, I'm not sure why you would need to clear the screen before doing anything. Otherwise, your code is fine.
I can't use #include<conio.h>.

ALso I end up getting this

*
**
***
****
*****
******
*******
********
*********
**********
***********
Last edited on
Simple fix?
1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>

int main()
         {
           for(int i=0;i<=10; i++)   // first loop
                   {
                       for(int j=0;j<=i; j++) // second nested loop
                              cout<<"**";
                     cout<<"\n";
                   }
           }
Last edited on
Thank you! Now I need a nested loop to create this pattern:
*
***
******
**********
***************
*********************
...Have you tried figuring it out by yourself?
Yes!
Alright so I got this:
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    for (int i = 0; i <= 10; i++)
    {
        for (int j = 0; j <= i + i; j++)
        {
            cout << "*";
        }
        cout << "\n";
    }
}

But I still don't get what I wanted.
Last edited on

srry didint read the question properly thats whyI ended up with this

*
**
***
****
*****
******
*******
********
*********
**********
***********
@daleth
to understand clearing screen before running run the program continueslly without using clrscr();
Is anyone there?
Here's a hint:

The number of asterisks change from 1 -> 3 -> 6 -> 10 -> 15 -> 21
Or:
1
1 + 2
1 + 2 +3
1 + 2 + 3 + 4
1 + 2 + 3 + 4 + 5
1 + 2 + 3 + 4 + 5 + 6
@rjryan94>
You should change your code like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int main()
{
    int s=0;
    for (int i = 1; i <= 10; i++)
    {
        for (int j = 0; j <s+i ; j++)
        {
            cout << "*";
        }
        s+=i;
        cout << "\n";
    }
    
    system ("Pause");
    return 0;
}
Thank you!
One last pattern:
□□□□□*
□□□□**
□□□***
□□****
□*****
******
□ representing space.
Last edited on
I think you've been given more than enough to finish it yourself :)
Seriously I need help.
True... @Zaita :p
Topic archived. No new replies allowed.