Kat H.

asked • 04/19/21

Triangle Printer 2. The existing code reads in a number and prints a series of rows. Modify it so it prints a triangle that looks like the ones shown below.

The existing code reads in a number and prints a series of rows. Modify it so it prints a triangle that looks like the ones shown below.


SizeShape
1
*
2
*
**
3
*
**
***
4
*
**
***
****


Hints:

  1. You can print a space with " "
  2. How does the number of spaces on each line relate to the current line number and the total number of lines?

Code:


#include <iostream>

using namespace std;


int main()

{

int size;

cin >> size;


for(int row = 1; row <= size; row++) {


cout << "*";

cout << endl;

}

}

1 Expert Answer

By:

Patrick B. answered • 04/20/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.