fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int rows = 5; // Define the number of rows for the pattern
  7.  
  8. for (int i = 1; i <= rows; ++i) { // Outer loop for rows
  9. // Print leading spaces for right alignment
  10. for (int j = 1; j <= (rows - i); ++j) {
  11. std::cout << " "; // Two spaces for alignment
  12. }
  13. // Print asterisks
  14. for (int k = 1; k <= i; ++k) {
  15. std::cout << "* "; // Asterisk followed by a space
  16. }
  17. std::cout << std::endl; // Move to the next line after each row
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
        * 
      * * 
    * * * 
  * * * * 
* * * * *