📚Intermediate

Print Inverted Hollow Star Pyramid

Print inverted hollow pyramid

Print an inverted hollow star pyramid with stars only on the borders.

C Program to Print Inverted Hollow Star Pyramid

inverted_hollow_pyramid.c
C
1#include <stdio.h>
2
3int main() {
4 int rows;
5
6 printf("Enter number of rows: ");
7 scanf("%d", &rows);
8
9 printf("\n");
10
11 for (int i = rows; i >= 1; i--) {
12 // Print leading spaces
13 for (int j = 0; j < rows - i; j++) {
14 printf(" ");
15 }
16
17 // Print stars and hollow spaces
18 for (int j = 1; j <= 2 * i - 1; j++) {
19 if (i == rows || j == 1 || j == 2 * i - 1) {
20 printf("*");
21 } else {
22 printf(" ");
23 }
24 }
25 printf("\n");
26 }
27
28 return 0;
29}
Output

Enter number of rows: 5

 

*********

* *

* *

* *

*

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples