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