fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int rows = 4; // Number of rows in the triangle
  6.  
  7. for (int i = 1; i <= rows; i++) {
  8. // Print spaces
  9. for (int j = i; j < rows; j++) {
  10. cout << " ";
  11. }
  12. // Print stars
  13. for (int k = 1; k <= (2 * i - 1); k++) {
  14. cout << "*";
  15. }
  16. cout << endl;
  17. }
  18.  
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
   *
  ***
 *****
*******