⭐⚡Beginner
Print Simple Pyramid Pattern
Print pyramid of stars
This program prints a pyramid pattern of stars using nested loops. The outer loop controls rows, inner loops control spaces and stars.
Program Code
pyramid_star.c
C
1#include <stdio.h>23int main() {4 int rows;5 6 printf("Enter number of rows: ");7 scanf("%d", &rows);8 9 for (int i = 1; i <= rows; i++) {10 // Print spaces11 for (int j = 1; j <= rows - i; j++) {12 printf(" ");13 }14 // Print stars15 for (int k = 1; k <= 2 * i - 1; k++) {16 printf("*");17 }18 printf("\n");19 }20 21 return 0;22}Output
Enter number of rows: 5
*
***
*****
*******
*********
Pattern Analysis
| Row | Spaces | Stars |
|---|---|---|
| 1 | 4 | 1 |
| 2 | 3 | 3 |
| 3 | 2 | 5 |
| 4 | 1 | 7 |
| 5 | 0 | 9 |
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials