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