⭐📚Intermediate
Print Hollow Star Pyramid
Print hollow pyramid
A hollow pyramid prints stars only on the borders of the pyramid.
Program Code
hollow_pyramid.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 leading spaces11 for (int j = 1; j <= rows - i; j++) {12 printf(" ");13 }14 15 // Print stars and spaces16 for (int k = 1; k <= 2 * i - 1; k++) {17 if (k == 1 || k == 2 * i - 1 || i == rows) {18 printf("*");19 } else {20 printf(" ");21 }22 }23 printf("\n");24 }25 26 return 0;27}Output
Enter number of rows: 5
*
* *
* *
* *
*********
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials