fork(1) download
  1. #include <iostream>
  2.  
  3. void testf(size_t n)
  4. {
  5. const size_t matSize = (n+1) * n + 1;
  6. char* mat = new char[matSize] {};
  7. for (size_t i = 0; i < matSize - 1; ++i)
  8. mat[i] = ' ';
  9. mat[matSize - 1] = 0;
  10.  
  11. for (size_t i = 0; i < n; ++i) {
  12. for (size_t j = 0; j <= i; ++j)
  13. mat[i*(n+1)+(n-j-1)] = '^';
  14. mat[i*(n+1) + n] = '\n';
  15. }
  16.  
  17. std::cout << "--- start " << n << "\n";
  18. std::cout << mat;
  19. std::cout << "--- end\n";
  20. }
  21.  
  22. int main()
  23. {
  24. testf(4);
  25. }
  26.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
--- start 4
   ^
  ^^
 ^^^
^^^^
--- end