Hollow Pyramid Pattern
A Hollow Pyramid Pattern resembles a solid pyramid but with the inner spaces left empty. This pattern is achieved by printing stars only at the edges of each row and leaving the inner space is blank. Each row of the pyramid consists of a combination of stars and spaces, strategically positioned to create the hollow effect.
Output
Enter the number of rows: 5
*
* *
* *
* *
*********
Free E-Books
Codes – Hollow Pyramid Pattern
Here is the codes of Hollow Pyramid Star Pattern,
#include <stdio.h> int main() { int rows; printf("Enter the number of rows: "); scanf("%d", &rows); for (int i = 1; i <= rows; 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
- Here set the Firstly, The program prompts for the user to enter the number of rows for the hollow pyramid.
- The it will iterates through each row using a
for
loop. - Within each row, it prints leading spaces to align the pyramid correctly.
- Then it determines whether to print a star or space based on the position within the row and whether it’s the last row.
- 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.