fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int rows, i, j, space;
  5.  
  6. // Number of rows for the pyramid
  7. printf("Enter the number of rows: ");
  8. scanf("%d", &rows);
  9.  
  10. // Loop for each row
  11. for (i = 1; i <= rows; i++) {
  12. // Print spaces
  13. for (space = 1; space <= rows - i; space++) {
  14. printf(" ");
  15. }
  16. // Print stars
  17. for (j = 1; j <= (2 * i - 1); j++) {
  18. printf("*");
  19. }
  20. // Move to the next line after each row
  21. printf("\n");
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5292KB
stdin
5
stdout
Enter the number of rows:     *
   ***
  *****
 *******
*********