Triangle pattern in C++

Level 392 keystrokes

The inner loop runs up to the current row number i, so row 1 has one star, row 2 two stars, up to four stars in row 4.

C++ code

// One row for each i from 1 to 4
1for (int i = 1; i <= 4; i++) {
// The limit is i, so each row is one star longer than the previous one
2 for (int j = 1; j <= i; j++) {
// Prints one star without a line break
3 cout << "*";
4 }
// Ends the row after i stars
5 cout << endl;
6}

Output

*
**
***
****
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • ;× 6
  • <× 6
  • +× 4
  • =× 4
  • "× 2
  • (× 2
  • )× 2
  • {× 2
  • }× 2
  • *× 1

More C++ examples at level 3

← C++ typing practice