Trangle with a base equal to its height

I'm supposed to practice nested for loops. There is one problem that asks for a pyramid with its base equal its height and I have come up with something that kind of looks like a pyramid where base == height. Is there a way to print a better triangle?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int SIZE = 40;
    for(int i = 0; i < SIZE; i++)
    {
        for(int j = 0; j < SIZE; j++)
        {
            if(i >= 2*j - SIZE - 1 && i >= -2 * j + SIZE && i  >= - SIZE)
                cout << "*";
            else
                cout << " ";
        }
        cout << endl;
    }

}


Last edited on
Topic archived. No new replies allowed.