# Nested for loops to create a Triangle

**URL:** <https://forum.kirupa.com/t/nested-for-loops-to-create-a-triangle/231478>\
**Category:** programming\
**Created:** [July 5, 2007, 5:21am UTC](https://forum.kirupa.com/t/nested-for-loops-to-create-a-triangle/231478 "2007-07-05T05:21:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NANO3](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@NANO3](https://forum.kirupa.com/u/NANO3)\
**Post date:** [July 5, 2007, 5:21am UTC](https://forum.kirupa.com/t/nested-for-loops-to-create-a-triangle/231478/1 "2007-07-05T05:21:20Z")

</div>

[RIGHT]\*\*\*\*\*\*\*\*\*\*

* * *

* * *

* * *

```
******
 *****
  ****
   ***
    **
     *

```

[LEFT]How would one go about creating that triangle in C++ using nested for loops?

```auto
for(int r = 0; r < 10; r++) {
        for(int c=0; c < r; c++) {
            cout << " ";
        }
        cout << "*";
        for(int c = 9; 9 > c > r; c--) {
            cout << "*";
        }

        cout << endl;
    }

```

> r = row, c = column

This is what I have so far, all it creates is the top line, and the diagonal of asterisks

Any help appreciated, thanks.

[/LEFT]  
[/RIGHT]
