Programming contests

50 Programming Exercise for Beginners

January 2, 2019 12:00 AM – December 31, 2019 12:00 AM

ASCII Triangles #2

Write a program that draws triangles on the standard output as shown in the sample output.

The first line of the input contains a positive integer t, which is the number of test cases. Each of the following t lines contains a positive integer n.

For each test case, the program must draw to the output a triangle with sides of length n, consisting of characters ' ' (space) and '*' (asterisk). The triangle is a right triangle, its perpendicular sides are in the first column and the last row, and the sides of the triangle are one unit thick. The last asterisk character in each line should be directly followed by the newline character (so there must be no space characters at the end of the lines). The outputs of two consecutive test cases should be separated by a blank line. Note that there must be no empty line following the last triangle!

Sample Input

  1. 2
  2. 4
  3. 6
download as text file

Output for Sample Input

  1. *
  2. **
  3. * *
  4. ****
  5. *
  6. **
  7. * *
  8. *  *
  9. *   *
  10. ******
download as text file

One possible solution is available in: main.c.

Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 03/01/2019