fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. std::string space(" ");
  8. std::string asterisk("*");
  9. int rows = 10;
  10.  
  11. for (int i = 1; i <= rows; ++i)
  12. {
  13. //special case for the first line
  14. if (i == 1)
  15. std::cout << asterisk << std::endl;
  16.  
  17. //for each of the other lines print 2 asterisks and the rest spaces
  18. if (i > 1 && i <= rows - 1)
  19. {
  20. //one at the start of the line
  21. std::cout << asterisk;
  22.  
  23. //print line - 2 spaces
  24. for (int j = 0; j < i - 2; ++j)
  25. std::cout << space;
  26.  
  27. //one at the end of the line
  28. std::cout << asterisk << std::endl;
  29. }
  30.  
  31. //special case for the last line
  32. if (i == rows)
  33. {
  34. for (int j = 1; j <= i; ++j )
  35. std::cout << asterisk;
  36. std::cout << endl;
  37. }
  38.  
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
*
**
* *
*  *
*   *
*    *
*     *
*      *
*       *
**********