Hollow Inverted Pyramid
Unlike regular Inverted Pyramids where each row has fewer stars than the preceding one, Hollow Inverted Pyramid Patterns feature stars only at the edges of each row, and the inner spaces is blank. This illusion creates the Inverted Pyramid Pattern with Hollow spaces inside.
Output
Enter the number of rows: 5
*********
* *
* *
* *
*
Free Hand-Written Notes
Codes – Hollow Inverted Pyramid
Here is the codes of Hollow Inverted Pyramid Pattern,
#include <stdio.h> int main() { int rows; printf("Enter the number of rows: "); scanf("%d", &rows); for (int i = rows; i >= 1; i--) { // Print leading spaces for (int j = 1; j <= rows - i; j++) { printf(" "); } // Print stars and spaces for (int j = 1; j <= 2 * i - 1; j++) { if (j == 1 || j == 2 * i - 1 || i == rows) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
Codes Explanation
- Firstly, The program shows the prompts to the user to enter the number of rows for the hollow inverted pyramid.
- Then it will iterates through each row using a
for
loop in descending order. - Next, Within each row, it prints leading spaces to align the pyramid correctly.
- Then it will determines the whether to print a star or space based on the position within the row and whether it’s the last row.
- After that, Stars are printed at the beginning and end of each row, leaving the inner spaces empty.
- Finally, it moves to the next line to start the next row.