(1) Ask the user to input a character. You will draw your right triangle with this character. (2) Ask the user to input the number of rows (integer). This will also signify the number of characters at the base of the triangle. (3) Use a nested loop to draw the triangle. The first line will only have one character but will now need to output enough spaces such that the character is output at the end of the row instead of the beginning. The number of characters on each line will increase by one until you have reached the base of your triangle. Include spaces between each character. Ex. Enter a character: * Enter number of rows: 7 * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Executable code:
#include <iostream>
using namespace std;
int main()
{
int space, rows;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i = 1, k = 0; i <= rows; ++i, k = 0)
{
for(space = 1; space <= rows-i; ++space)
{
cout <<" ";
}
while(k != 2*i-1)
{
cout << "* ";
++k;
}
cout << endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.