I have to ask the user for a size (an integer), and output a triangle of that many rows as follows:
*
***
*****
*******
p.s. note that the triangle is displayed from left to right. this triangle has 2 be displayed from right to left. thanks!
I have to ask the user for a size (an integer), and output a triangle of that many rows as follows:
*
***
*****
*******
p.s. note that the triangle is displayed from left to right. this triangle has 2 be displayed from right to left. thanks!
Which language you want to do it in? Atleast mention that...
I am new to C++ but I thought I might try just giving this a shot. So there might be better ways of doing this but it seems to work.
#include <iostream>
using namespace std;
int main ()
{
short int numRows;
cout << "How many rows do you want your triangle?\n";
cin >> numRows;
cout << "\n";
for (int row = 1; row <= numRows; row++)
{
for (int col1 = 0; col1 < numRows - row; col1++)
{
cout << " ";
}
for (int col2 = 0; col2 < row; col2++)
{
cout << "*";
}
cout << "\n";
}
return 0;
}
Bookmarks