### C++ triangle pattern

Hi, I would like some help with this problem.
I have to create a program that will create this pattern:
http://gyazo.com/124b7f7235749e8cdf0367eb29483000.png

Here is what I have so far:

 ``123456789101112131415161718192021222324`` ``````#include #include using namespace std; int main() { cout<<"\nEnter the no.: \n"; int i,j,n; cin>>n; for(i=1;i<=n;i++) { j=i; for(;j;j--) cout<<"*"; j=n; for(;j;j--) cout<<" "; cout<
 ```* ************ ************ * ** *********** *********** ** *** ********** ********** *** **** ********* ********* **** ***** ******** ******** ***** ****** ******* ******* ****** ******* ****** ****** ******* ******** ***** ***** ******** ********* **** **** ********* ********** *** *** ********** *********** ** ** *********** ************ * * ************```

What you have so far generates something like this:
 ```*..... **..... ***..... ****..... *****.....```

For the sake of clarity, I replaced space by a dot.

Try this:
 ``1234567891011`` `````` for (i=1; i<=n; i++) { // 1a for(j=i; j; j--) cout<<"*"; // 1b for(j=n-i+1; j; j--) cout<<"."; cout<

I labelled the code 1a and 1b, as this is the first of four main sections of the image.

Concentrate now on part 2a and 2b.

After that, the second half is a mirror-image of the first, so the code can be more or less cut and pasted for that.

Hope this helps.
Last edited on
Topic archived. No new replies allowed.