fork download
  1. // Nicolas Ruano CS1A Chapter 2, Pp. 83, #15
  2.  
  3. /*************************************************************************
  4. *
  5. *------------------------------------------------------------------------*
  6. * Output is when the program releses the result of a set of stars forming*
  7. * a shape of a triangle. *
  8. * -----------------------------------------------------------------------*
  9. * Input *
  10. * The number of stars being provided and how much to craft a triangle *
  11. * *
  12. * Output *
  13. * The number of stars shoewcased a a triangular shape built on stars *
  14. *************************************************************************/
  15.  
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main() {
  20. int rows = 4; // Number of rows in the triangle
  21.  
  22. for (int i = 1; i <= rows; i++) {
  23. // Print spaces
  24. for (int j = i; j < rows; j++) {
  25. cout << " ";
  26. }
  27. // Print stars
  28. for (int k = 1; k <= (2 * i - 1); k++) {
  29. cout << "*";
  30. }
  31. cout << endl;
  32. }
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5260KB
stdin
Standard input is empty
stdout
   *
  ***
 *****
*******