Nested Loop * unique tree problem (i've searched already)
I need help figuring out how to design a code to output:
1 2 3 4 5 6 7 8 9
|
*
***
*
***
*****
*
***
*****
*******
|
...and so on based on two input values. I've got the general concept down i think but am having trouble making the triangle repeat.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include<iostream>
using namespace std;
int main()
{
int rows = 0;
int lines;
cout<< "Number of lines: "<< endl;
cin>> lines;
for(int i=0; i< lines; i++)
{
for(int j = (lines -1 -i); j> 0; j--)
{
cout<<" ";
}
for(int k=0; k < (i*2 +1); k++)
{
cout<< "*";
}
cout<<endl;
}
return 0;
}
|
When I output this it gives me:
1 2 3 4 5
|
*
***
*****
*******
|
...based on the two values i put in, so I know I'm close. I just need a little help to finish.
Last edited on
Topic archived. No new replies allowed.