* shapes

how to get this output but in same level with explanation please


1
2
3
4
5
6
7
8
9
10
*
***
*****
*******
*********
         *
       ***
     *****
   *******
 *********
Last edited on
What code do you have so far?
We're not going to write your code for you.

#include <iostream>

using namespace std;
int main()
{
int n;
cin>>n;

for (int a = 1; a <= n; a++)
{
for (int b = 1; b <= a; b++)
{
cout<<"*"<<" ";
}

cout<<endl;
}



for (int y = 1; y <= n; y++)
{
for(int r = n-y; r>0; r--)
{
cout<<" ";
}

for(int x = 1; x <= y; x++)
{
cout<< "*" <<" ";
}

cout << endl;
}





return 0;

}
Sorry for not writing the code in the question and I want only how to make them at the same level and thank you for your reply
Instead of having two separate outer for loops to control 2 sets of rows, you'll have one outer for loop that controls a single set of rows. The numbers for the pattern on the right have to adjust for no longer starting at the very left side of the screen.
Topic archived. No new replies allowed.