How can I change my code to get a different triangle output.

Hi, I have this bit of code that I wrote to print a triangle that looks like this: https://imgur.com/EYKlAM0
What I want to do, is change it to look like this: https://imgur.com/6HYPFjO

I've tried looking everywhere to try and get some help, but I'm pretty lost. I'm pretty new to this, so I'm sorry if this is just a stupid question. Thanks for the help.

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
26
27
28
29
30
#include<iostream>
using namespace std;
int main()
{
	int row;
	int col;
	int numRows;
	int numCols;
	char chr;
	
	cout << "enter num rows: ";
	cin >> numRows;
	cout << "enter num cols: ";
	cin >> numCols;
	cout << "enter char: ";
	cin >> chr;

	for (row = 1; row <= numRows; row++)
	{
		for (col = 1; col <= numCols; col++)
		{
			if (col <= row)
			{
				cout << chr;
			}
		}
		cout << endl;
	}	

}
Something like this?
1
2
3
4
5
6
7
8
			if (col <= numRows - row)
			{
				cout << ' ';
			}
			else
			{
				cout << chr;   
			}
Last edited on
Yes!

Thank you so much.
Topic archived. No new replies allowed.